BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
shawnchen0321
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

sas-innovate-white.png

🚨 Early Bird Rate Extended!

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.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 637 views
  • 1 like
  • 2 in conversation