Can you please recode this variable for me; Married =1 and not married =2. Recode: marital status ([married (4,5) and not married (1,2,3,6,7,8)
< High school= 1 and not > High school= 2. Recode: education [< High school (1,2)] and [> High school (3,4,5,6)]
@Ossy wrote:
Can you please recode this variable for me; Married =1 and not married =2. Recode: marital status ([married (4,5) and not married (1,2,3,6,7,8)
< High school= 1 and not > High school= 2. Recode: education [< High school (1,2)] and [> High school (3,4,5,6)]
What did you try? Did it run? If not what error did you get? Share your log.
Did it run but not do what you want? In what way was the result wrong?
Not able to start? Show some example input data and the expect result for that example data. Make sure to consider edge cases.
Hello @Ossy
It is always very helpful if your provide a sample of the actual data, following these instructions (and not Excel or screen captures). Please do this in all future questions, and even for this question. Without this sample of your data, I can only guess that the values are not character, they are numeric, and should not be enclosed in quotes. But also please keep in mind that what @Tom said, you haven't told us what went wrong with your code, again we are guessing.
Nevertheless, here is my solution:
proc format;
value maritalf 1,2,3,6,7,8='Not Married' 4,5='Married';
run;
data want;
set have;
format marital maritalf.;
run;
Statements like:
If education < High school='1' then Highschool=1;
is not going to work.
Do you really have two separate variables named HIgh and School?
And even if you did you cannot just list two variables next to each other without any operator in between them.
What are the NAMES of the variables in your SURVEY datasets? (Not the LABELS attached to the variables.) If the names include spaces then you will need to do two things.
1) Make sure the VALIDVARNAME option is set to ANY instead of the normal setting of V7.
2) Use NAME LITERALS in the code when referencing the variables with spaces (or other characters not normally allowed in names of objects in SAS).
Assuming you did have two variables named EDUCATION and HIGHSCHOOL what would it mean to test if one is larger than the other? Are those variables NUMERIC or CHARACTER? If they are character then comparisons will be down lexigraphically (the first character is comparied. If they are the same then the second character is compared. etc. So values like '11' or '12' and less than values like '2'.)
I'm not sure why the word "recode" is used. Custom formats would be a much better approach, doesn't require you to create a new character variable.
Can you please recode this variable for me; Married =1 and not married =2. Recode: marital status ([married (4,5) and not married (1,2,3,6,7,8)
< High school= 1 and not > High school= 2. Recode: education [< High school (1,2)] and [> High school (3,4,5,6)]
I recoded the variable but did not get a positive result. Here is my recoded version. Please let me know where I made mistakes. Thanks
if marital='4' then married='1';
else if marital='5' then married='1';
else if marital='1' then married='0';
else if marital='2' then married='0';
else if marital='3' then married='0';
else if marital='6' then married='0';
else if marital='7' then married='0';
else if marital='8' then married='0';
IF age < 50 then agey='1';
else if age > 50 then agey='2';
RUN;
If education < High school='1' then Highschool=1;
else if education < High school=2 then Highschool=1;
else if education > High school=3 then Highschool='0';
else if education > High school=4' then Highschool='0';
else if education > High school=5' then Highschool='0';
else if education > High school=6' then Highschool='0';
DUPLICATE THREAD
Moderator ... please add this thread into https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949495#M42657
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.