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
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;
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;
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.
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.