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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.