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
;;;;
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;
;;;;
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;
;;;;
Yes this works but how about if I have two words at the beginning like "Severe Weather"
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.
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!
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.