I have a string
example 1: abcdefgs:456:fdkweu/:START:41A:45583993:START:60A:6483829992:STOP:59:hagdsu2381ygu:73:
example 2:
hsdgsdgcj:64:54:adcg6edd:START:71A:274765765:START:84A:26357457454:STOP:59:2237fdguef
I want to delete any string between the 1st START and STOP strings i.e. the output should look like below. I want to delete everything that is underline above:
Output 1:
abcdefgs:456:fdkweu/:START::STOP:59:hagdsu2381ygu:73:
Output 2:
hsdgsdgcj:64:54:adcg6edd:START::STOP:59:2237fdguef
I tried the below solution of 1st identifying the string I want to remove between the first START and STOP, which I was able to identify with the code below. Next I am trying to use tranward to drop this identified string from the original column, but with no success.
My code:
data want;
data have;
length newstring $1000;
startpos = index(string,":START:");
endpos = index (string, startpos+7, endpos-(startpos+7));
drop startpos endpos;
string = tranward(string, new string, "");
run;
I am able to code for the first part and it works fine where I can identify the sub string I want to drop from the main string. However, I am not able to drop the identified string from the main string, using tranward. I am unable to query it correctly.
Please help with the red part of the code.
Thank you
data want;
set have;
startpos=find(string,":START:"0)+6;
endpos=find(string,":STOP:");
string = cats(substr(string,1,startpos),substr(string,endpos));
run;
data want;
set have;
startpos=find(string,":START:"0)+6;
endpos=find(string,":STOP:");
string = cats(substr(string,1,startpos),substr(string,endpos));
run;
data have;
length eg $500;
eg='abcdefgs:456:fdkweu/:START:41A:45583993:START:60A:6483829992:STOP:59:hagdsu2381ygu:73:';
output;
eg='hsdgsdgcj:64:54:adcg6edd:START:71A:274765765:START:84A:26357457454:STOP:59:2237fdguef';
output;
run;
data want;
set have;
length want $250;
want=cats(substr(eg,1,index(eg,'START')+5),substr(eg,index(eg,'STOP')-1));
run;
Both of these solutions work very well.
data have;
length eg $500;
eg='abcdefgs:456:fdkweu/:START:41A:45583993:START:60A:6483829992:STOP:59:hagdsu2381ygu:73:';
output;
eg='hsdgsdgcj:64:54:adcg6edd:START:71A:274765765:START:84A:26357457454:STOP:59:2237fdguef';
output;
run;
data want;
set have;
want=prxchange('s/start.+stop/START::STOP/i',1,eg);
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.