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!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: