☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 05-12-2023 09:31 AM
(2835 views)
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!
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
UNTESTED CODE
data want;
set have;
where=find(customer_comment,'KEYword');
remaining_text=substr(customer_comment,where+length('KEYword'));
run;
--
Paige Miller
Paige Miller
7 REPLIES 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
UNTESTED CODE
data want;
set have;
where=find(customer_comment,'KEYword');
remaining_text=substr(customer_comment,where+length('KEYword'));
run;
--
Paige Miller
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much.. it worked..
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, do you have access to Visual Text Analytics? This would be straightforward with LITI syntax in a concept rule. Otherwise you might want to try regular expressions. For example you could use PRXMATCH to match against the pattern then return the remained or the string.
You might try something like this if the data is simple enough:
data want;
set have;
*find pattern location (add 7 to discard keyword);
position = prxmatch('/KEYword/',text) + 7;
*substring remainder of text;
if position gt 7 then out = substr(text,position);
keep text position out;
run;
You might try something like this if the data is simple enough:
data want;
set have;
*find pattern location (add 7 to discard keyword);
position = prxmatch('/KEYword/',text) + 7;
*substring remainder of text;
if position gt 7 then out = substr(text,position);
keep text position out;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much.. this works tooo
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
and.. Unfortunately I don't have access to Visual Text Analytics. I work with SAS EG. However your solution worked.. So all good.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much.. All these solutions do work