BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_New_User1
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    startpos=find(string,":START:"0)+6;
    endpos=find(string,":STOP:");
    string = cats(substr(string,1,startpos),substr(string,endpos));
run;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
data want;
    set have;
    startpos=find(string,":START:"0)+6;
    endpos=find(string,":STOP:");
    string = cats(substr(string,1,startpos),substr(string,endpos));
run;
--
Paige Miller
novinosrin
Tourmaline | Level 20
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;
SAS_New_User1
Obsidian | Level 7

Both of these solutions work very well. 

Ksharp
Super User
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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 832 views
  • 2 likes
  • 4 in conversation