## calculating the OR for Categorical Variables

Solved
Occasional Contributor
Posts: 5

# calculating the OR for Categorical Variables

How do you write a code in SAS that will enable you to calculate the odds ratio (OR) for a categorical variable such as BMI?

Accepted Solutions
Solution
‎04-09-2016 09:03 PM
Super User
Posts: 20,755

## Re: calculating the OR for Categorical Variables

Your dataset only has one value for Exercise so you have 2X1 table?

You should really post sample data.

Here's a worked through example of logistic regression that is really similar to what you're trying to do.

http://www.ats.ucla.edu/stat/sas/dae/logit.htm

My only suggestion would be to change the model line to add the expb option.

`model admit = gre gpa rank/expb;`

expb provides the exponentiated value of the estimates

All Replies
Super User
Posts: 20,755

## Re: calculating the OR for Categorical Variables

Depends a bit on what you're trying to do, but either proc freq or proc logistic are good starting points.

If if you need more help, please post some sample data and explain what you're trying to calculate.

The documentation has good examples and example data if you can't provide your actual data.

Occasional Contributor
Posts: 5

## Re: calculating the OR for Categorical Variables

Hi Reeza,

Thank you for your reply. I have a data set containing a variable called BMI (a categorical variable with 3 levels: normal, overweight and obese) and a variable called Exercise (a categorical variable with 3 levels: not answered, yes, and no). I want to determine which BMI group has the highest odds of not exercising. I am trying to compare the odds ratios for each group but the codes I have tried to run aren't producing the odds ratio. I have tried the following code to no avail:

if Exercise = 3;

run;

tables Exercise * BMI / OR;

run;

Super User
Posts: 10,214

## Re: calculating the OR for Categorical Variables

That is because your contingency table is 3x3 not 2x2 .

Try to use General Logistical Regression .

Occasional Contributor
Posts: 5

## Re: calculating the OR for Categorical Variables

Thank you Xia. I will try that.

Solution
‎04-09-2016 09:03 PM
Super User
Posts: 20,755

## Re: calculating the OR for Categorical Variables

Your dataset only has one value for Exercise so you have 2X1 table?

You should really post sample data.

Here's a worked through example of logistic regression that is really similar to what you're trying to do.

http://www.ats.ucla.edu/stat/sas/dae/logit.htm

My only suggestion would be to change the model line to add the expb option.

`model admit = gre gpa rank/expb;`

expb provides the exponentiated value of the estimates

Occasional Contributor
Posts: 5

## Re: calculating the OR for Categorical Variables

@Reeza Thank you very much for your assistance. I am making progress. Lol.

Super User
Posts: 11,822

## Re: calculating the OR for Categorical Variables

Any chance your data is from BRFSS or similar complex structured survey? If so you'll want to use Proc SurveyLogistic to use the sampling information correctly.

Occasional Contributor
Posts: 5

## Re: calculating the OR for Categorical Variables

@ballardw Yes it is BRFSS data. I will try that as well. Thank you.

☑ This topic is solved.