Hi everyone!

Thanks in advance for your time and help. I have the following problem....Some of the data I received has all the ages of individuals as a string variable, with some ages of children specified as X Months or Z Yr and X Months. I would like to extract the number of months, so just X, from ages reported as X months and I would like to extract years and months together into a single number with a decimal between them. For example:
  • 6 Months extracted as 6
  • 1 Yr 2 Months extracted as 1.2
The current code I have been using to extract the number of months, gives me the number plus the letter M, and I am not sure how to even begin with extracting the year and months together. The code I have been using for months:
  • gen age_num = ustrregexs(0) if ustrregexm(age, "(^[0-9]+)(\s)([Months])")