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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.