Skip to content
Advertisement

SAS proc SQL: Extract number in front of the word ‘Month’ or ‘Months’

I want to extract a number from a string where it is directly followed by the word ‘Month’ or ‘Months’.

The search should be case insensitive and the text to look in typically looks like

In db2 I use this with:

How can I convert this to SAS proc sql?

Advertisement

Answer

A simple solution

In this

  • find with the i modifier looks case insensitive for the string month in myText
  • substr returns the part in front of it
  • scan with -1 as position returns the last word before month
  • input applies the format 8. to read that word as a number of up to 8 digits

Disclaimer

  • This code is not tested
  • It will only find one occurance of month in a string
  • It will also find a number in front of monthly, for instance
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement