Here is my desired output and sample data in datalines. Can someone help me with the Perl code to get the number that is between PT and M or PT and M? It's elapsed time since dose. I know there has to be a quicker way than using scan function.
data times;
input pceltm $;
datalines;
PT30M
PT2H
PT4H
PT6H
;
run;
Thanks!
data times;
input pceltm $;
datalines;
PT30M
PT2H
PT4H
PT6H
;
run;
data want;
retain r;
if _N_ = 1 then r = prxparse('/PT(\d+)[HM]/');
set times;
if prxmatch(r, pceltm) then time = prxposn(r, 1, pceltm);
run;
data times;
input pceltm $;
datalines;
PT30M
PT2H
PT4H
PT6H
PT6C
;
run;
data want;
set times;
pid=prxparse('/(?<=PT)\d+(?=M|H)/');
call prxsubstr(pid,pceltm,p,l);
if p then want=substr(pceltm,p,l);
drop p l pid;
run;
It works but I only know prxmatch and prxchange. Can you explain what p and l do? I got that pid is the pattern id.
data times;
input pceltm $;
datalines;
PT30M
PT2H
PT4H
PT6H
;
run;
data want;
retain r;
if _N_ = 1 then r = prxparse('/PT(\d+)[HM]/');
set times;
if prxmatch(r, pceltm) then time = prxposn(r, 1, pceltm);
run;
Amazing! Thanks both!
data times;
input pceltm $;
datalines;
PT30M
PT2H
PT4H
PT6H
;
run;
data want;
set times;
time=prxchange('s/(PT)(\d+)((M|H))/$2/',-1,pceltm);
run;
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.