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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.