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

Hi 

I want to change the month number to a season for the variable camonth 

month from 1 to 5 = spring 

month from 9 to 12 = autumn 

months from 6 to 8 others 

in data HO

 I did this code which results in missing data

 

if camonth = 1 then camonth = autumn;
if camonth = 2 then camonth = autumn;
if camonth = 3 then camonth = autumn;
if camonth = 4 then camonth = autumn;
if camonth = 5 then camonth= autumn;
if camonth = 6 then camonth = other;
if camonth = 7 then camonth = other;
if camonth = 8 then camonth = other;
if camonth = 9 then camonth = spring;
if camonth = 10 then camonth = spring;
if camonth = 11 then camonth = spring;
if camonth = 12 then camonth = spring;

Regards 

camonth 
1
2
3
4
5
6
7
8
9
10
11
12

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am going to assume that cammonth is a numeric variable, therefore you cannot put character data into it.  You have a few methods to do what you want, most simple is a format which you apply to the data -  don't know what software your using so this is simple SAS code:

proc format;
  value season
    1-5="Autumn"
    6-8="Other"
    9-12="Spring";
run;

data want;
  set have;
  format cammonth season.;
run;

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am going to assume that cammonth is a numeric variable, therefore you cannot put character data into it.  You have a few methods to do what you want, most simple is a format which you apply to the data -  don't know what software your using so this is simple SAS code:

proc format;
  value season
    1-5="Autumn"
    6-8="Other"
    9-12="Spring";
run;

data want;
  set have;
  format cammonth season.;
run;
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 971 views
  • 1 like
  • 2 in conversation