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."
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!
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.