BookmarkSubscribeRSS Feed
Achieng
Quartz | Level 8

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; 
5 REPLIES 5
Reeza
Super User
*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
Quartz | Level 8
thank you very much.
There are no Proc freq data.
This is what I am getting in the logs

NOTE: Variable househouldID_1 is uninitialized.
NOTE: There were 3301 observations read from the data set WORK.IMPORT.
NOTE: The data set WORK.STEP2 has 3301 observations and 367 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 4142.87k
OS Memory 39596.00k
Timestamp 15/03/2021 10:33:48 PM
Step Count 128 Switch Count 3
Page Faults 0
Page Reclaims 805
Page Swaps 0
Voluntary Context Switches 14
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 22536

Reeza
Super User
NOTE: Variable househouldID_1 is uninitialized.

I made a typo in the code above, notice the extra u. Please fix the code by correcting the variable name, re-running it and posting the output.
Achieng
Quartz | Level 8
Thank you Reeza,
It has worked.
the output table is too large.
this part of the log

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 *name of output data set is Step2;
74 data Work.STEP2;
75
76 *name of input data set is Import;
77 set Work.IMPORT;
78
79 *Household Education is set to 1 for householdID_2 =1, else 0;
80 if householdID_2 = 1 then household_ED=1;
81 else household_ed = 0;
82
83 run;
NOTE: There were 3301 observations read from the data set WORK.IMPORT.
NOTE: The data set WORK.STEP2 has 3301 observations and 366 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 4175.78k
OS Memory 40364.00k
Timestamp 15/03/2021 11:11:39 PM
Step Count 183 Switch Count 3
Page Faults 0
Page Reclaims 670
Page Swaps 0
Voluntary Context Switches 17
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 22536
84
85 *check results;
86 proc freq data=Step2;
87 table HouseHold_ED*HOUSEHOLDID_2*EducationLevel / list;
88 run;
NOTE: There were 3301 observations read from the data set WORK.STEP2.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.02 seconds
user cpu time 0.02 seconds
system cpu time 0.01 seconds
memory 3560.93k
OS Memory 39352.00k
Timestamp 15/03/2021 11:11:39 PM
Step Count 184 Switch Count 8
Page Faults 0
Page Reclaims 534
Page Swaps 0
Voluntary Context Switches 40
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 1064

Thnak youveery very much

ballardw
Super User

@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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 515 views
  • 0 likes
  • 3 in conversation