Programming the statistical procedures from SAS

calculating the OR for Categorical Variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

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
Grand Advisor
Posts: 16,893

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

 

View solution in original post


All Replies
Grand Advisor
Posts: 16,893

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:

 

data=answer2;

set answer;

if Exercise = 3;

run;

 

proc freq data=answer;

tables Exercise * BMI / OR;

run;

 

 

Grand Advisor
Posts: 9,452

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
Grand Advisor
Posts: 16,893

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.

Grand Advisor
Posts: 10,043

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 400 views
  • 2 likes
  • 4 in conversation