BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michokwu
Quartz | Level 8

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 
BIOL10128DCWC10128
ANT102102
PSY125125
SOC101101
SPAN23302330
HIST15001500
BCS-205205
BCS-132132
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Try it this way:

 

want = compress(have, , 'kd');

As the third parameter, kd = keep digits

View solution in original post

7 REPLIES 7
ghosh
Barite | Level 11
want=compress(have, '', 'A');
smantha
Lapis Lazuli | Level 10
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;
michokwu
Quartz | Level 8

Thanks! This works but it includes special characters. How do I get only the numbers?

ghosh
Barite | Level 11
Did not not see my response, that is what 'A' modifier does.
want=compress(have, '', 'A');
It says, replace alpha with nothing
michokwu
Quartz | Level 8

Thank you! Some of observations still include special characters.

Astounding
PROC Star

Try it this way:

 

want = compress(have, , 'kd');

As the third parameter, kd = keep digits

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 5128 views
  • 2 likes
  • 4 in conversation