Given a character variable Y of length 1, create a new variable X7 storing values as defined in the following table.
Y | X8 |
---|---|
'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:
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.
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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.