X20l,p5,op3
cX3z,p4,op2(1)
Need help on extracting values that are after letter X and before first coma.
for :X20l,p5,op3----20l
for:cX3z,p4,op2(1)--3z
Try this:
data temp;
length extracted_value $ 10;
input char_str $ 1-20;
extracted_value = prxchange('s/^[^X]*X(.*?)\x2C.*$/$1/',1,char_str);
datalines;
X20l,p5,op3
cX3z,p4,op2(1)
;
As suggested, a regular expression will do the job:
data temp;
if _n_ = 1 then prxId + prxParse("/X(\w+?),/i");
length extracted_value $ 10;
input char_str $ 1-20;
if prxMatch(prxId, char_str) then
extracted_value = prxPosn(prxId, 1, char_str);
drop prxId;
datalines;
X20l,p5,op3
cX3z,p4,op2(1)
;
proc print data=temp noobs; run;
Remove the "i" in the pattern if the letter X at the beginning cannot be lowercase.
If it appeared only once, that would be easy.
data have;
input x $40.;
cards;
X20l,p5,op3
cX3z,p4,op2(1)
;
run;
data want;
set have;
pid=prxparse('/(?<=x).+?(?=,)/i');
call prxsubstr(pid,x,p,l);
want=substr(x,p,l);
run;
data want;
set have;
pid=prxparse('/(?<=x)[^,]+(?=,)/i');
call prxsubstr(pid,x,p,l);
want=substr(x,p,l);
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.