SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

VARIABLE CHARACTER

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

VARIABLE CHARACTER

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

 


Accepted Solutions
Solution
‎05-09-2018 09:54 AM
Super User
Super User
Posts: 9,384

Re: VARIABLE CHARACTER

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


All Replies
Solution
‎05-09-2018 09:54 AM
Super User
Super User
Posts: 9,384

Re: VARIABLE CHARACTER

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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