BookmarkSubscribeRSS Feed
4301
Calcite | Level 5

I am trying to create a dummy variable for my categorical variable(ethnic) using if else command. But the output only displays 0.

 


if ethnic="black" then dublack= 1; else dublack= 0;
if ethnic="cauca" then ducauca=1;else ducauca=0;
run;

 

 
3 REPLIES 3
ballardw
Super User

Print out some values of your variable ethnic. Make sure the spelling is the same as you are using in code.

"black" is not the same as "Black" or "BLACK" in code.

 

Also check to see if there is a FORMAT associated with that variable other than a simple $w. (w would be an integer, no idea what it may be though from your code should be a minimum of 5. If there is a different format then you may not be seeing values to code against.

 

Plus, why do you want a dummy variable at all? For many of the processes that would require dummy internally  such as regression would be done by the SAS regression procedure by placing the variable on a CLASS statement as well as a Model statement.

4301
Calcite | Level 5

Thank you so much, it worked. It should be "BLACK" instead of "black". I am using proc traj command, so there would not be class statement.

Rick_SAS
SAS Super FREQ

Even for procedures that do not support the CLASS statement, there is no need to generate dummy variables yourself. Several SAS procedures support methods to generate dummy variables and output them to a data set for analysis. Consider using the GLMSELECT procedure, as described in the article, "The best way to generate dummy variables in SAS."

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 783 views
  • 1 like
  • 3 in conversation