BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data test(keep=Disaster);

set test1;

run;

 

Sample Output

Disaster

Hurricane Harvey
Hurricane Beula
Hurricane Agnes 
Wildfires

 

If the variable begins with Hurricane  I want to delete it and just show the word after the blank space.  I looked at compress, trim, strip functions however no examples.  How can I accomplish this ??     

3 REPLIES 3
novinosrin
Tourmaline | Level 20

data have;
input disaster $20.;
datalines;
Hurricane Harvey
Hurricane Beula
Hurricane Agnes
Wildfires
;

data want;
set have;
if scan(disaster,1)='Hurricane' then _disaster=scan(disaster,2);
else _disaster=disaster;
run;

 

or with IFC function:

data want;
set have;
/*if scan(disaster,1)='Hurricane' then _disaster=scan(disaster,2);*/
/*else _disaster=disaster;*/
_disaster=ifc(scan(disaster,1)='Hurricane' , scan(disaster,2), disaster);
run;

Astounding
PROC Star

I guess hurricanes usually receive one-word names.  Just in case there is more than one word following "Hurricane" this might be a little safer:

 

data want;
set have;
if upcase(scan(disaster,1))='HURRICANE' then _disaster=substr(disaster,11);
else _disaster=disaster;
run;

ChrisNZ
Tourmaline | Level 20

or

data WANT;
  set HAVE;
  if upcase(DISASTER) =: 'HURRICANE ' then DISASTER = substr(DISASTER,11);
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 788 views
  • 0 likes
  • 4 in conversation