Dear friend,
I am trying to create a new variable.
I am evaluating the education level of household members. But I have an educational level for everyone in the study.
Educationlevel (levels 1-5) In my new coding, I want educationlevel =0, bt all others equals=1 for householdID_1, Please help.
data=Work.IMPORT;set Work.IMPORT;
else if HouseholdID_1=1 the do;
else If Educationlevel="1" & HouseholdID_1="1" then Household_ED="0";
else If Educationlevel="2" & HouseholdID_1="2" then Household_ED="1";
else If Educationlevel="3" & HouseholdID_1="3" then Household_ED="1';
else If Educationlevel="4" & HouseholdID_1="4" then Household_ED="1";
If Educationlevel="5" & HouseholdID_1="5" then Household_ED="1";
run;
*name of output data set is Step2;
data Work.STEP2;
*name of input data set is Import;
set Work.IMPORT;
*Household Education is set to 1 for householdID_1 =1, else 0;
if householdID_1 = 1 then household_ED=1;
else household_ed = 0;
run;
*check results;
proc freq data=Step2;
table HouseHold_ED*HOUSEHOLDID_1*EducationLevel / list;
run;
If this doesn't give you what you want, please post the otuput from the PROC FREQ and show us what you want each value coded as, compared to what it's currently coded as.
EDIT: To correct spelling issue in a variable name.
@Achieng wrote:
Dear friend,
I am trying to create a new variable.
I am evaluating the education level of household members. But I have an educational level for everyone in the study.
Educationlevel (levels 1-5) In my new coding, I want educationlevel =0, bt all others equals=1 for householdID_1, Please help.
data=Work.IMPORT;set Work.IMPORT; else if HouseholdID_1=1 the do; else If Educationlevel="1" & HouseholdID_1="1" then Household_ED="0"; else If Educationlevel="2" & HouseholdID_1="2" then Household_ED="1"; else If Educationlevel="3" & HouseholdID_1="3" then Household_ED="1'; else If Educationlevel="4" & HouseholdID_1="4" then Household_ED="1"; If Educationlevel="5" & HouseholdID_1="5" then Household_ED="1"; run;
@Achieng wrote:
Dear friend,
I am trying to create a new variable.
I am evaluating the education level of household members. But I have an educational level for everyone in the study.
Educationlevel (levels 1-5) In my new coding, I want educationlevel =0, bt all others equals=1 for householdID_1, Please help.
data=Work.IMPORT;set Work.IMPORT; else if HouseholdID_1=1 the do; else If Educationlevel="1" & HouseholdID_1="1" then Household_ED="0"; else If Educationlevel="2" & HouseholdID_1="2" then Household_ED="1"; else If Educationlevel="3" & HouseholdID_1="3" then Household_ED="1'; else If Educationlevel="4" & HouseholdID_1="4" then Household_ED="1"; If Educationlevel="5" & HouseholdID_1="5" then Household_ED="1"; run;
Mismatched quote is the reason for missing values and likely warnings in the LOG (eventually).
When asking why something is not behaving it is import to copy from the log the data step or procedure with all the notes and warnings. Copy the text and paste into a text box on the forum opened using the </> icon to preserve formatting.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.