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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.