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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: