I'm creating dummy variables for the first time!
I am using data from NHANES.
I have a variable smoke_hx where 0= never smoked, 1=past smoker, 2=current smoker.
I want to create the variables ever_smoked1 that is a dummy for smoke_hx=1 and ever_smoked2 which is a dummy for smoke_hx=2. Never smoked is the reference group.
How do I create these dummy variables? I've read a bunch of explanations but nothing is making sense!
Good to know! But for this class, my professor is requiring us to manually create them. This is the code I have. Not sure if it's correct.
@Reeza wrote:
Why?
If the CLASS statement exists with in the procedure it will do the dummy coding for you, no need to do that manually.
data data2;
set data1;
if smoke_hx=1 then ever_smoked1=1;
else ever_smoked1=0;
if smoke_hx=2 then ever_smoked2=1;
else ever_smoked2=0;
run;
Good to know! But for this class, my professor is requiring us to manually create them. This is the code I have. Not sure if it's correct.
@Reeza wrote:
Why?
If the CLASS statement exists with in the procedure it will do the dummy coding for you, no need to do that manually.
data data2;
set data1;
if smoke_hx=1 then ever_smoked1=1;
else ever_smoked1=0;
if smoke_hx=2 then ever_smoked2=1;
else ever_smoked2=0;
run;
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.