Hi, I have a variable called "Customer_Comment " (a string) with free text and I need to extract rest of the comment after specific word.
Word word word word word KEYword word word word word word
Word word KEYword word word word word
Word word word word word
Word word word word word word word word KEYword word word word.
The comments are something like above and what I need is to extract all the text after the key word, if the Keyword exists in the comment, so the result would be like below..
word word word word word.
word word word word.
word word word.
I have tried few functions such as SCAN,FIND,SUBSTR but couldn't get it done, so any help is much appreciated!
UNTESTED CODE
data want;
set have;
where=find(customer_comment,'KEYword');
remaining_text=substr(customer_comment,where+length('KEYword'));
run;
UNTESTED CODE
data want;
set have;
where=find(customer_comment,'KEYword');
remaining_text=substr(customer_comment,where+length('KEYword'));
run;
want=prxchange('s/.*?KEYword(.*)/$1/',-1,have);
as for example in
DATA demo;
LENGTH have want $100;
have="Word word word word word KEYword word1 word2 word3 word4 word5";
want=prxchange('s/.*?KEYword(.*)/$1/',-1,have);
RUN;
- Cheers -
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.