Hi, researchers.
I would like to substring a person's name from a description.
It seems to have a rule like XXX will become, XXX will step.
Therefore, how do I substring person's name before will?
data have;
input x $50.;
cards;
A Barr Dolan will become
A Brooke Seawell will step
Aharon Schwartz will become
Maureen F Morrison will become
Matthew Bilunas will become
;
run;
Output Want
Text Name
A Barr Dolan will become A Barr Dolan
A Brooke Seawell will step A Brooke Seawell
Aharon Schwartz will become Aharon Schwartz
Thanks in advance.
data want;
set have;
where=findw(x,'will',' ');
name=substr(x,1,where-2);
run;
This method fails for someone who has the name "will" in their name, such as the famous political writer George F. Will or the famous actor Will Smith, unless we can depend on the fact that all names are properly capitalized in the data set. It also fails if will is capitalized as "Will", or if will does not exist in the string.
data want;
set have;
where=findw(x,'will',' ');
name=substr(x,1,where-2);
run;
This method fails for someone who has the name "will" in their name, such as the famous political writer George F. Will or the famous actor Will Smith, unless we can depend on the fact that all names are properly capitalized in the data set. It also fails if will is capitalized as "Will", or if will does not exist in the string.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.