BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Agent1592
Pyrite | Level 9

Dear Sas Community:

I have a simple dataset but I am trying to keep just the first word in the column.

My have data is:

 

data have;
  infile datalines dsd truncover;
  input _NAME_:$50. ;
datalines4;
Hurricane 1980 Allen;
Hurricane 1991 Bob;
Freeze 1990 - California;
Freeze 1998 - California;
Hurricane/ Flood;
Flood/ Hurricane;
Severe Weather 2011; ;;;;

My want table is:

How can I achieve that efficeintly?

data want;
  infile datalines dsd truncover;
  input _NAME_:$50. ;
datalines4;
Hurricane;
Hurricane;
Freeze;
Freeze ;
Hurricane;
Flood;
Severe Weather ;;;;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data have;
  length firstword $ 20;
  infile datalines dsd truncover;
  input _NAME_:$50. ;
  firstword = scan(_name_,1);
  drop _name_;
datalines4;
Hurricane 1980 Allen;
Hurricane 1991 Bob;
Freeze 1990 - California;
Freeze 1998 - California;
Hurricane/ Flood;
;;;;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
data have;
  length firstword $ 20;
  infile datalines dsd truncover;
  input _NAME_:$50. ;
  firstword = scan(_name_,1);
  drop _name_;
datalines4;
Hurricane 1980 Allen;
Hurricane 1991 Bob;
Freeze 1990 - California;
Freeze 1998 - California;
Hurricane/ Flood;
;;;;
--
Paige Miller
Agent1592
Pyrite | Level 9

Yes this works but how about if I have two words at the beginning like "Severe Weather"

PaigeMiller
Diamond | Level 26

Then you need to develop a rule that covers all such cases where you want the second word (and also indicates when you don't want the second word) and then program that rule.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 734 views
  • 1 like
  • 2 in conversation