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

Hi 

I'm a new SAS 9.4 user, trying to compute a new column using a IF-THEN statement. The below table is my weather data, the column I am trying to compute is season, for example under the column name Season; from the 1st of Sep 2017 to 30th of November 2017 from the date column will also appear under Season as Spring17. 

EM_G_3-1617082324715.png

 

 

 

Below is an unsuccessful attempt. 

EM_G_2-1617082124379.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this:

if '01jan2020'd < DATE < '31mar2020'd then SEASON='Winter2020';

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

Like this:

if '01jan2020'd < DATE < '31mar2020'd then SEASON='Winter2020';

EM_G
Fluorite | Level 6

This worked thank you. 

I just had to add an = after both < to include both the first and last date in that season. 

Thanks again, great help. 

Shmuel
Garnet | Level 18

Alternative way to assign value to season is by checking the month:

data want;
 set have;
      length season $8;
       mm = month(date);
       if 03 le mm le 05 then season = 'Automn'; else
       if 06 le mm le 08 then season = 'Winter' ; else
       if 09 le mm le 11 then season = 'Spring'; else
       if mm in (01 02 12) then season = 'Summer';
       season = cat(season, put(date,year2.));
run;
EM_G
Fluorite | Level 6

I like this solution, but the trouble is I have three different years and need to be able to identify them in season also. By checking the month only I will have three summers etc. Can I specify year also?

Shmuel
Garnet | Level 18
@EM_G wrote:

I like this solution, but the trouble is I have three different years and need to be able to identify them in season also. By checking the month only I will have three summers etc. Can I specify year also?


You missed the line where I concatenate the year to the season derived from the month format:

season = cat(season, put(date,year2.));

and, of course, you can replace the year2. format with year4. format, if preferd.

 

Thus you are free to work with any year and any number of years.

 

EM_G
Fluorite | Level 6

My apologies, I didn't realize how that worked. I understand now and this works also, so thank you.

 

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
  • 6 replies
  • 1484 views
  • 4 likes
  • 3 in conversation