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

How do I create a dummy or indicator variable for "sweetness" variable for the data below? Say use 1="2" and 0="4"?

 

data brand;
	input preference moisturecontent sweetness @@;
	datalines;
	64 4 2 73 4 4 61 4 2 76 4 4 72 6 2 80 6 4 
	71 6 2 83 6 4 83 8 2 89 8 4 86 8 2 93 8 4
	88 10 2 95 10 4 94 10 2 100 10 4
	;
run;
proc print;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data want;
   set brand;
   if sweetness=2 then dummy=1;
   else if sweetness=4 then dummy=0;
   else;
run;

proc print data=want;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

data brand;
	input preference moisturecontent sweetness @@;
	datalines;
	64 4 2 73 4 4 61 4 2 76 4 4 72 6 2 80 6 4 
	71 6 2 83 6 4 83 8 2 89 8 4 86 8 2 93 8 4
	88 10 2 95 10 4 94 10 2 100 10 4
	;
run;

data dummy;
set brand;
indicator_sweet=sweetness=2;
run;
PeterClemmensen
Tourmaline | Level 20
data want;
   set brand;
   if sweetness=2 then dummy=1;
   else if sweetness=4 then dummy=0;
   else;
run;

proc print data=want;
run;
PaigeMiller
Diamond | Level 26

So, I am certainly reading between the lines here, but it seems to me that you have asked the wrong question, and the answers you received don't steer you any closer to a better solution.

 

@JUMMY you have asked a huge number of questions here in this forum about modeling in SAS. So why would you need dummy variables? You probably don't. Almost every SAS modeling procedure does not need dummy variables to be  created before you do the modeling. The SAS procedures have a CLASS statement, which does the unpleasant and tedious work of creating dummy variables for you. So, bottom line, don't create the dummy variables yourself if you are modeling in almost every SAS modeling procedure, use the CLASS statement.

 

Next topic:

So ... not reading between the lines here ... again, I'm not happy with the answers you received ...

 

How do I create a dummy or indicator variable for "sweetness" variable for the data below? Say use 1="2" and 0="4"?

 

Generally, there's no reason to do this either. You don't need dummy variables. You already have two "class" levels, "2" and "4". Converting to zeros and ones is just extra work that provides no benefit if you are going to treat them as categories.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Bingo!!!

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
  • 4 replies
  • 710 views
  • 1 like
  • 4 in conversation