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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 538 views
  • 1 like
  • 2 in conversation