## Creating New Variable with a given table

Occasional Contributor
Posts: 7

# Creating New Variable with a given table

Given a character variable Y of length 1, create a new variable X7 storing values as defined in the following table.

YX8
'E''East'
'S''South'
'W''West'
'N''North'
Other Value''

I am just a beginner with SAS.
I tried this question, but I keep failing...:smileycry: The major problem is that I don't know what this question is telling me to do.

What I tried:

Data g;

y= 1 & 2;

if Y = 1

then do; E = 'East'; S="South"; W = 'WEST';N = 'North'; end;

else if Y > 1

then do; Other_Value = '';end;

run;

Failing miserably...S.O.S!!! :smileycry:

Super User
Posts: 9,599

## Re: Solving Triangle Problems with SAS Program

Is it not just asking you to do an if statement (or case for that matter).  I.e. if Y which is of type charater, length of 1, has the single character 'E' as value, then in variable X7 should contain 'East'.  So:

set rawdata;

attrib x7 format=\$20.;

if y='E' then x7='East';

if y='W' then x7='West';

...

run;

Alternatively maybe they are asking you to create a format and apply it:

proc format;

value \$compass 'E'='East' 'W'='West' 'S'='South' 'N'='North';

run;

set rawdata (rename=(y=x7));

format x7 \$compass.;

run;

Note - I realize there are many ways of doing this, if/then/else, select case etc.  This just seems to be the most basic.

Super User
Posts: 23,773

## Re: Solving Triangle Problems with SAS Program

Given a character variable Y of length 1, create a new variable X7 storing values as defined in the following table.

Mapping values are in the table.

You're being asked to recode a variable.