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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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