DATA Step, Macro, Functions and more

Extract digits

Reply
Super Contributor
Posts: 673

Extract digits

If I have a drug name FEIBA VH 650, I use ("/ \d{1,5}\.?\d{0,4}/") to extract digits from it.

How to extract 651 or 1200 from FEIBA VH 651-1200?
Contributor
Posts: 74

Re: Extract digits

if the format is always ddd-dddd (d for a digit) and there is no digit in strings in front of it, then you may toggle with anydigit(drugname) and index(drugname, '-'). or you can scan the string with delimitator space and '-' and see what you get from the data.
Valued Guide
Posts: 2,177

Re: Extract digits

without the regular expression handling,, the extraction of number strings is fairly straight forward in SAS9. Just compress(), keeping blank, dash and digits. Then scan() using blank and dash as delimiters.
I think it should be something like
scan( compress( original, ' -)', 'kd' ). 1, '- ' )

PeterC
Ask a Question
Discussion stats
  • 2 replies
  • 212 views
  • 0 likes
  • 3 in conversation