DATA Step, Macro, Functions and more

calculate odds ratio (OR)

Reply
Occasional Contributor
Posts: 8

calculate odds ratio (OR)

I have a group of variables I'd like to calculate their ORs, if possible all once and including 95% CI 

 

Here is what the data looks like. The categorical variable Race (white or black) used for two comparison groups. I want to calculate the ORs between W and B for Var1-Var5. Is there a good/easy way to get the ORs and 95%CIs for all the variables? Thanks. 

 

Obs Race Var1 Var2 Var3 Var4 Var5
  1     W      1        0       1       1      0
  2     B       0        1       0       1      1
  3     B      0         1       0       1      1
  4    W      0         0       0       0      0
  5    W      1         0       1       0      0
  6    W      1        1        1       0      1
  7    B       1         0       1       0      0
  8    W      1         1      1        1      1
  9    B      1          0       1       1      0
 10   B      0         1        0       0      1

Super User
Posts: 17,912

Re: calculate odds ratio (OR)

Have you tried PROC FREQ? 

Super User
Posts: 17,912

Re: calculate odds ratio (OR)

Here's an example with PROC FREQ. You may need to switch around the variables to ensure your analysis is correct. 

 

data have;
    input Obs Race $ Var1 Var2 Var3 Var4 Var5;
    cards;
  1     W      1        0       1       1      0
  2     B       0        1       0       1      1
  3     B      0         1       0       1      1
  4    W      0         0       0       0      0
  5    W      1         0       1       0      0
  6    W      1        1        1       0      1
  7    B       1         0       1       0      0
  8    W      1         1      1        1      1
  9    B      1          0       1       1      0
 10   B      0         1        0       0      1
 ;
run;

proc print data=have;
run;

proc freq data=have;
    table race * (var1-var5)/ Oddsratio;
run;
Occasional Contributor
Posts: 8

Re: calculate odds ratio (OR)

Thank you Reeza for your quick and helpful response. I run into another problem that some of the count of a response is zero. if we use traditional method to calculate ORs, one of the cells in a 2X2 table would be 0, it would cause the OR is zero or not be able to be calculated. Do you have any suggestion about how to deal with such a situation? Thanks again. 

 

e.g.                exposed  not exposed

     Disease        0              3

No-disease        210         340

SAS Super FREQ
Posts: 3,483

Re: calculate odds ratio (OR)

The odds ratio for a 2x2 table is defined as

OR = (n11*n22) / (n12*n21)

so the odds ratio for your example is 0.

Occasional Contributor
Posts: 8

Re: calculate odds ratio (OR)

Thanks for your response. Technically, yes, it would be zero, but in a practical term, it is not very meaningful. I think there should be some way to be able to estimate the risk (OR) even when the frequency of one outcomes is 0. 

SAS Super FREQ
Posts: 3,483

Re: calculate odds ratio (OR)

From a frequentist point of view, the estimate is zero. Are you looking for a Bayesian analysis?

Super User
Posts: 17,912

Re: calculate odds ratio (OR)


Xiaoyi wrote:

Thanks for your response. Technically, yes, it would be zero, but in a practical term, it is not very meaningful. I think there should be some way to be able to estimate the risk (OR) even when the frequency of one outcomes is 0. 


It means that your sample size was too small for the event you're trying to observe.

Occasional Contributor
Posts: 8

Re: calculate odds ratio (OR)

That's true. The sample given here is just an example for easy calculation in SAS. My real data set has more than 60 000 observations. 

 

one example of the counts from  2X2 table from my data:                        exposed          not-exposed

                                                                                                 disease         0                          8

                                                                                             no disease        2254                63700

It is a rare disease situation. Some would say the OR is zero or can't be calculated. I am looking for a way to estimate the risk/association between factors in a more meaningful way. Some said adding 0.5 to each sell. I am not sure if it would work with SAS or if it is biased. 

 

Any suggestion would be appreciated. Thanks. 

 

Xiaoyi

 

 

Ask a Question
Discussion stats
  • 8 replies
  • 152 views
  • 0 likes
  • 3 in conversation