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!
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.