Trying to figure out how to model a categorical predictor in your regression? Done this code a million times but can never remember the syntax for the class statement? Want to generate exponentiated estimates and confidence intervals? We'll give examples for binary, 3 levels, 4 levels, and stratified. ## Binary PredictorFor all of these code snippets, define &data, &outcome, and &var with your data set, outcome variable, and predictor variable. &let data=<dataset>; Here we've used proc genmod, and called on logistic regression using the logit link and binomial distribution. The estimate statement puts a value of 1 in for the predictor variable. The "exp" option has SAS exponentiate the OR and 95% CI for us. You'll want to go to the row labeled Exp(&VAR), over to the estimate and 95% CI column. ## Multi-Level Categorical PredictorThis example is for an age category variable, which can easily have more than 3 or 4 levels. Here, &var is "agecat", and the reference value is the youngest age group, 18-29. You'd need to replace the estimate "OR LABEL" &var... statement with your own labels. The tricky part here is how many zeros? You can see for each subsequent level, we add a zero, extending the 1 out. You'll see later even when we make the reference value a different level, it's similar.
## Different Reference ValueThis variable has 3 levels. We're choosing level 2 (private insurance), to be the reference. You can see that when we do our estimate statement, we don't skip over 0 1 for level 2, but instead go sequentially like in the last example. If instead we made the reference level 3, we would adjust our labels to reflect that, and use the same 1 and 0 1 designation in the estimate statements.
## Stratified Logistic Regression with Categorical PredictorsWhat if you want to stratify? First, sort your data set by the strata variable. Then run your analyses as above, but add a -by- statement. Your output will be for strata=0 and strata=1 (or more if you have more levels). You won't get an overall output, so you'll need to run that separately.
Enjoy! Feel free to bookmark. |

Bailey DeBarmore is a doctoral student at the University of North Carolina at Chapel Hill studying epidemiology. Find her on Twitter@BaileyDeBarmore and blogging for the American Heart Association on the Early Career Voice blog. |

0 Comments

## Leave a Reply.

Practical solutions for conducting great epidemiology methods. Transparency in code. Attitude of constant improvement.

Appreciate our stuff?

All

Bailey DeBarmore

Data Visualization

Excel

Paul Zivich

P Values

Python

Regression

SAS

Stata

ZEpid

September 2020

April 2019

September 2018

August 2018

July 2018

June 2018

May 2018