Hello,
I want to change every character that not ST or LI to " "
I wrote this code:
data _null_;
a='ELISG_ST#AT_#S_STD#D="Y"';
b=prxchange('s/[^(ST|LI)]/ /',-1,a);
put a=;
put b=;
run;
a=ELISG_ST#AT_#S_STD#D="Y"
this is the output:
b=LIS ST T S ST
this is the desire output:
LI ST ST
how can I use not without this [] brackets that create class group?
^ can only be used in a [] class.
But this works too if you want another way:
data _null_;
a='ELISG_ST#AT_#S_STD#D="Y"';
b=prxchange('s/.*?((ST)|(LI))?.*?/$1/',-1,a);
put a= / b=;
run;
b=LISTST
data _null_;
a='ELISG_ST#AT_#S_STD#D="Y"';
length b $ 100;
do i=1 to length(a)-1;
temp=substr(a,i,2);
if temp in ('ST' 'LI') then b=catx(' ',b,temp);
end;
put a=;
put b=;
run;
Opps. Delete the OUTPUT statement.
OK. No problem.
data _null_;
a='ELISG_ST#AT_#S_STD#D="Y"';
length b $ 200;
start=1;
end=length(a);
pid=prxparse('/ST|LI/');
call prxnext(pid,start,end,a,p,l);
do while(p>0);
b=catx(' ',b,substr(a,p,l));
output;
call prxnext(pid,start,end,a,p,l);
end;
put a=;
put b=;
run;
Thanks for your help
I am doing this as part of learn regular expression, so I am not looking for a solution to this specific problem.
I try to understand how to do it only with regular expression.
if I want to change ST and LI
I will use the following code:
data _null_;
a='ELISG_ST#AT_#S_STD#D="Y"';
b=prxchange('s/(ST|LI)/ /',-1,a);
put a=;
put b=;
run;I am looking for a way to put not on (ST|LI)
any Ideas?
^ can only be used in a [] class.
But this works too if you want another way:
data _null_;
a='ELISG_ST#AT_#S_STD#D="Y"';
b=prxchange('s/.*?((ST)|(LI))?.*?/$1/',-1,a);
put a= / b=;
run;
b=LISTST
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.