Hello Experts,
I have a variable that includes both characters and numbers and does not follow any specific coding standard as it has been obtained from multiple sources. I would just like to collect the numbers. I can't use substr because the codes are different. Is there a way I can do this?
Thank you
have | want |
BIOL10128DCWC | 10128 |
ANT102 | 102 |
PSY125 | 125 |
SOC101 | 101 |
SPAN2330 | 2330 |
HIST1500 | 1500 |
BCS-205 | 205 |
BCS-132 | 132 |
Try it this way:
want = compress(have, , 'kd');
As the third parameter, kd = keep digits
want=compress(have, '', 'A');
data _new;
informat have $32.;
input have $ var2;
want=compress(compress(have,' +/*-%','A'));
cards;
BIOL10128DCWc 10128
ANT102 102
PSY125 125
SOC101 101
SPAN2330 2330
HIST1500 1500
BCS-205 205
BCS-132 132
;;;
run;
Thanks! This works but it includes special characters. How do I get only the numbers?
Thank you! Some of observations still include special characters.
Try it this way:
want = compress(have, , 'kd');
As the third parameter, kd = keep digits
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.