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 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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