BookmarkSubscribeRSS Feed

How to create dummy variables - Categorical Variables

Started ‎11-01-2016 by
Modified ‎11-01-2016 by
Views 9,026

If you're doing some analysis with categorical data and you're using a proc that does not support the CLASS statement, then you may need to create dummy variables.

 

I won't go into what dummy variables are, but how to create them using GLMMOD.

 

Problem: Create dummy variables for sex and age from sashelp.class dataset.

 

Solution:

/*Run model within PROC GLMMOD for it to create design matrix
Include all variables that might be in the model*/
proc glmmod data=sashelp.class outdesign=want outparm=p;
class sex age;
model weight = sex age height;
run;

/*Create rename statement automatically
THIS WILL NOT WORK IF YOUR VARIABLE NAMES WILL END UP OVER 32 CHARS*/
data p;
set p;
if _n_=1 and effname='Intercept' then var='Col1=Intercept';
else var= catt("Col", _colnum_, "=", catx("_", effname, vvaluex(effname)));
run;

proc sql;
select var into :rename_list separated by " "
from p;
quit;


/*Rename variables*/
proc datasets library=work nodetails nolist;
modify want;
rename &rename_list;
run;quit;


proc print data=want;
run;

The WANT dataset can now be used to model with the dummy variables present.

 

Here are some additional articles about how to create dummy variables in SAS. They contain discussion and examples:

A design matrix is a numeric matrix that representes all variables (continuous and categorical) in a regression model.

Version history
Last update:
‎11-01-2016 08:23 AM
Updated by:
Contributors

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

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags