BookmarkSubscribeRSS Feed
Takumi
Calcite | Level 5

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:


2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:

data with_additional_variable;

     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;

data with_additional_variable;

     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.

Reeza
Super User

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.


Google: recode variable site:lexjansen.com

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 865 views
  • 0 likes
  • 3 in conversation