BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
westbestern
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
westbestern
Obsidian | Level 7

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;



View solution in original post

3 REPLIES 3
Reeza
Super User
Why?
If the CLASS statement exists with in the procedure it will do the dummy coding for you, no need to do that manually.
westbestern
Obsidian | Level 7

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;



Reeza
Super User
Your code looks correct then. You can check it though, using proc freq.

proc freq data=data2;
table smoke_hx*ever_smoked1 / list;
table smoke_hx*ever_smoked2 / list;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 703 views
  • 1 like
  • 2 in conversation