HI,
Below is the input:
BOM_ZEB_MIC_1002214_API_1002214_K304330
BOM_EVR_MIC_11000000002328_API_11000000002328_243
And out put required is:
1002214_API_1002214_K304330
11000000002328_API_11000000002328_243
I want to remove the first 3 Words as you can see in output.What function to be used for this ?
Kindly help
KR
Sanchit Arora
Use the substr() function with the findc() function and the "d" paramer:
data have; length text new_text $2000; text="BOM_ZEB_MIC_1002214_API_1002214_K304330"; new_text=substr(text,findc(text,"1","d")); output; text="BOM_EVR_MIC_11000000002328_API_11000000002328_243"; new_text=substr(text,findc(text,"1","d")); output; run;
Use the substr() function with the findc() function and the "d" paramer:
data have; length text new_text $2000; text="BOM_ZEB_MIC_1002214_API_1002214_K304330"; new_text=substr(text,findc(text,"1","d")); output; text="BOM_EVR_MIC_11000000002328_API_11000000002328_243"; new_text=substr(text,findc(text,"1","d")); output; run;
Thank you so much for the solution. It its working
Do bear in mind that it looks for the first occurence of a number in the string, and then substrings from there. If your data like the given examples you will be fine, just remember the above.
HI,
I found new problem . Sorry i have to mention earlier .
I have a Input like:
BOM_WAR_MIC_R740193 Output coming as :740193
BOM_EVR_MIC_CD5T: Output coming as :5T
I need output as:
R740193
CD5T:
Yes, thats why I mentioned it. Basically the idea is to find a logical pattern in the data (as I don't have the data I can't tell you), then find that data and substring from that point. Now say that your data is always separated by MIC, then you would do:
substr(text,find(text,"MIC")+4);
This will find the text MIC, then from the start position of MIC + four (so we don't get MIC_ in the output) substring out to the end of the string. Maybe if its always from the third underscore you could do:
new_string=strip(tranwrd(string,cats(scan(string,1,"_"),"_",scan(string,2,"_"),"_",scan(string,3,"_"),"_"),""));
What the above does is scan out the first three parts as delimited by the underscore and screate a string with the underscores, that text then being removed from the string by use of tranwrd.
Its really up to how your data looks and what the logical delimiter is.
An alternative would be using Perl Regular Expression:
The following code will replace the first 3 words by nothing, meaning: removing them.
new_text=prxchange('s/^([^_]+_){3}//o', -1, text);
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.