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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.