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-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1178 views
  • 1 like
  • 3 in conversation