Hello
What is the way to take only numeric (numbers) from a string ?
For example:
Data t;
input string;
cards;
abcd25_fmt
gfhhff31_qr
jdhh4gt_r
;
run;
I need to get:
25
31
4
Another way is to use the compress function with "k" and a positiv list:
want= compress(string,'0123456789','k');
For details of the compress function, see: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lefunctionsref&docsetTarg...
The correct answer actually depends on details that you haven't specified. What about decimal points? What about minus signs? What about multiple sets of digits? What should each of these become?
gfhhff3.14_qr
gfhhff3a1_qr
gfhhff-31_qr
gfhhff3-1_qr
gfhhff3+1_qr
gfhhff+31_qr
If you want to learn about the COMPRESS function (such as the meaning of "A"), you can read it here:
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.