Good Evening, Please advise what is the best way to remove certain text in a string in dataset.
Example: Assignment was sent to John Smith with the reason and status as Pending
Assignment was sent to Peter Smith with the reason and status as Complete.
Output I'm looking for is:
Assignment was sent to John Smith
Assignment was sent to Peter Smith
I want to remove all the text that appears after the name (John smith, Peter Smith) in the above examples.
Thank you
You need to post more examples and rules you are taking account of.
data have;
input x $80.;
cards;
Assignment was sent to John Smith with the reason and status as Pending
Assignment was sent to Peter Smith with the reason and status as Complete.
;
data want;
set have;
pid=prxparse('/[A-Z][a-z]+\s+[A-Z][a-z]+/');
if prxmatch(pid,x) then do;
call prxsubstr(pid,x,p,l);
want=substr(x,1,p+l);
end;
drop pid p l;
run;
Since we don't know how many words make up the name, it's easier to use with
as the marker.
data HAVE;
input WORDS $80.;
cards;
Assignment was sent to John Smith with the reason and status as Pending
Assignment was sent to Peter Smith with the reason and status as Complete.
run;
data WANT;
set HAVE;
WORDS2 = substr(WORDS, 1, index(WORDS, ' with'));
run;
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.