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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.