# How to Calculate Odds Ratios in SAS (With Example)

In statistics, an odds ratio tells us the ratio of the odds of an event occurring in a treatment group compared to the odds of an event occurring in a control group.

We often calculate an odds ratio when performing an analysis on a 2-by-2 table, which takes on the following format:

To calculate an odds ratio in SAS, we can use the PROC FREQ statement.

The following example shows how to use this statement in practice.

## Example: Calculating an Odds Ratio in SAS

Suppose 50 basketball players use a new training program and 50 players use an old training program. At the end of the program we test each player to see if they pass a certain skills test.

The following table shows the number of players who passed and failed, based on the program they used:

Suppose we would like to calculate an odds ratio to compare the odds of a player passing the skills test using the new program compared to using the old program.

We can use the following syntax with PROC FREQ in SAS with the chisq and relrisk statements to calculate this odds ratio along with relative risk values:

```/*create dataset*/
data my_data;
input result \$ program \$ count;
datalines;
Passed New 34
Passed Old 39
_Failed New 16
_Failed Old 11
;
run;
/*calculate odds ratio*/
proc freq data=my_data;
weight count;
tables program * result / chisq relrisk;
run;```

The first table in the output shows the frequency of each combination of the categorical variables:

The last table in the output shows the odds ratio that we’re interested in:

The odds ratio turns out to be 0.5994.

We would interpret this to mean that the odds that a player passes the test by using the new program are just .5994 times the odds that a player passes the test by using the old program.

In other words, the odds that a player passes the test are actually lowered by about 40.06% by using the new program.

We can also use the values in the 95% confidence Limits columns of the output to construct the following 95% confidence interval for the odds ratio:

95% confidence interval for the odds ratio: [0.2449, 1.4666].

We are 95% confident that the true odds ratio between the new and old training program is contained in this interval.

Since the confidence interval contains the odds ratio value of 1, it means the odds ratio is not statistically significant.

In other words, we know from the odds ratio that the odds of a player passing using the new program are lower than the odds of passing using the old program, but the difference between these odds is not actually statistically significant.

## Additional Resources

The following tutorials provide additional information about odds ratios:

May 13, 2024
April 25, 2024
April 19, 2024