I have a string as below
4527488//ahdjs}hdu:34ahdgj:60A:283748 8q79979A B B C Dajhed}{-5 jkqedhkkh36929 82939 A D.
I want to remove everything after " }{-5" , including "}{-5" i.e. desired output is as below:
4527488//ahdjs}hdu:34ahdgj:60A:283748 8q79979A B B C Dajhed
there can be a } or { or - or 5 before or after the above combination but never in the combined "}{-5" combination format. I want to remove everything after this "}{-5" combination, including the combination.
Please try the below code
data have;
input string &:$200.;
datalines4;
4527488//ahdjs}hdu:34ahdgj:60A:283748 8q79979A B B C Dajhed}{-5 jkqedhkkh36929 82939 A D.
;;;;
data want;
set have;
pos=index(string,'}{');
string2=substr(string,1,pos-1);
run;
One way
data example; x="4527488//ahdjs}hdu:34ahdgj:60A:283748 8q79979A B B C Dajhed}{-5 jkqedhkkh36929 82939 A D."; newx = substr(x,1,index(x,"}{-5") -1); run;
The Index function returns the character position where the target string starts. So you want to end one position prior to that, so there is a -1. Substr selects characters in positions between the two position number including the ends.
Please try the below code
data have;
input string &:$200.;
datalines4;
4527488//ahdjs}hdu:34ahdgj:60A:283748 8q79979A B B C Dajhed}{-5 jkqedhkkh36929 82939 A D.
;;;;
data want;
set have;
pos=index(string,'}{');
string2=substr(string,1,pos-1);
run;
please try the perl regular expression
data want;
string="4527488//ahdjs}hdu:34ahdgj:60A:283748 8q79979A B B C Dajhed}{-5 jkqedhkkh36929 82939 A D.";
string2=prxchange('s/(.*)(\}{.*)/$1/oi',-1,string);
run;
data want; string="4527488//ahdjs}hdu:34ahdgj:60A:283748 8q79979A B B C Dajhed}{-5 jkqedhkkh36929 82939 A D."; string2=prxchange('s/(}{.*)//oi',-1,strip(string)); run;
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!
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.