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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 418 views
  • 0 likes
  • 3 in conversation