Good morning,
I would like to extract the numbers from the sample dataset 'Have'. I list the result I would like to get in the 'Want' dataset.
data Have; infile datalines delimiter='#'; input Comments : $200. ; datalines; UGESTAGE=34 5/7 WKS # UGESTAGE=35WKS # UGESTAGE=33.4 WKS # UGESTAGE= 24 WKS ; run; data Want; infile datalines delimiter='/'; input UGESTAGE ; datalines; 34 / 35 / 33 / 24 ; run;
Hello,
One way :
want=input(prxchange("s/^[^\d]*(\d+).*$/$1/",1,Comments), best.);
Hello,
One way :
want=input(prxchange("s/^[^\d]*(\d+).*$/$1/",1,Comments), best.);
data Have;
infile datalines delimiter='#';
input Comments : $200. ;
datalines;
UGESTAGE=34 5/7 WKS #
UGESTAGE=35WKS #
UGESTAGE=33.4 WKS #
UGESTAGE= 24 WKS
;
run;
data Want;
set have;
want=scan(comments,1,,'kd');
run;
Somehow, I used PERI code is not working properly. I changed to use Ksharp's code, it works fine. Thanks much!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.