BookmarkSubscribeRSS Feed
Reeza
Super User

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.

1 REPLY 1
Rick_SAS
SAS Super FREQ

Here are some 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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 4042 views
  • 7 likes
  • 2 in conversation