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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.