PinkyL
PinkyL

Reputation: 361

How to extract number and/or string in sas

Generic drug names are sometimes formatted like this:

X-Y Tab 5-325 MG, where the drug of interest is X and the amount is 5. A different column has pre-extracted this as: 5 MG-325 M or 10 MG-325 depending on the amount of X.

Is there a way I can extract the amount that is associated with a MG? I am not sure if it's possible to use IS LIKE since the column is character format, and then converting the amount since there is a space between the number and MG.

Upvotes: 0

Views: 405

Answers (1)

DCR
DCR

Reputation: 15700

the examples you are providing suggest that the pre-extracted string is a number space MG. If that's always true you can use the scan function to get the number part of your string.

amount = scan(pre-extracted,1,' ');

you can do this in a data step. Look up the scan function and you can see other options that may help you customize this further.

Upvotes: 2

Related Questions