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;
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.
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.
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."
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.