For a simple estimate of a risk ratio in a 2x2 table, FREQ is giving a value that is too large. In the example below, the Experimental group has 4 out of 336 subjects with the attribute (1.19%), and the Control group has 7 out of 355 (1.97%). That produces an estimated RR of 0.6037. Simple, right?
However, FREQ gives RR=0.8042. I can't figure how FREQ got that value!!!
I think this is a glitch, but I don't see a FIX for this. I'm running SAS 9.4 TS Level 1M4 on a X64_10PRO platform.
proc freq data=test;
table Outcome * Treatment / relrisk ;
run;
The FREQ Procedure
|
|
| ||||||||||||
|
|
| ||||||||||||
|
|
|
Statistics for Table of Outcome by tmt |
Odds Ratio and Relative Risks Statistic Value
0.1737 | 2.0649 |
0.5114 | 1.2647 |
0.6121 | 2.9452 |
The documentation section "Odds Ratio and Relative Risks for 2x2 tables" defines the RELRISK computation.
"The relative risk is the ratio of the row 1 risk to the row 2 risk in a 2x2 table. The column 1 risk in row 1 is the proportion of row 1 observations that are classified in column 1, which can be expressed as"
p1 = n11 / n1 which for your table is 348/680
p2 = n21 / n2 which for your table is 7/11
The column 1 relative risk is computed as
R = p1/p2 which for your data is 0.8042, as reported.
Thanks for the reply. Probably worth a caution to users.
@Rick_SAS wrote:The documentation section "Odds Ratio and Relative Risks for 2x2 tables" defines the RELRISK computation.
"The relative risk is the ratio of the row 1 risk to the row 2 risk in a 2x2 table. The column 1 risk in row 1 is the proportion of row 1 observations that are classified in column 1, which can be expressed as"
p1 = n11 / n1 which for your table is 348/680
p2 = n21 / n2 which for your table is 7/11
The column 1 relative risk is computed as
R = p1/p2 which for your data is 0.8042, as reported.
Thanks for the reply. It's probably worth a caution to users who prefer the RR to the OR.
If you want the correct answer for a risk ratio in SAS for a 2x2 table or a stratified 2x2 table using the FREQ procedure, you need to be careful with the configuration and the coding. We found this out the hard way!
For example, for a generic 2x2 table where the RR is the ratio of the Experimental to the Control proportion:
|
| Outcome | |
| Yes | No | |
Tmt | Experimental | 4 | 332 |
Control | 7 | 348 |
It is extremely important on the “order” of both the Treatment and Outcome label values.
For example, the data coding below for “tmt” and “outcome” will not give you what you want!
DATA tab2x2 ;
input tmt $ outcome $ freq ;
datalines ;
Exp Yes 4
Exp No 332
Ctl Yes 7
Ctl No 348
;
However, if you “order” the label values correctly, as shown below, for example:
|
| Outcome | |
| Yes | No | |
Tmt | Experimental | 1, 1 | 1, 2 |
Control | 2, 1 | 2, 2 |
DATA tab2x2;
input tmt $ outcome $ freq;
datalines;
1Exp 1Yes 4
1Exp 2No 332
2Ctl 1Yes 7
2Ctl 2No 348
;
This will give you the correct RR estimate.
Also, in the TABLE statement, the “tmt” factor must be listed before the “outcome” variable. For stratified tables, the stratum factor must be the first variable (e.g. stratum*tmt*outcome):
proc FREQ data=tab2x2 ;
TABLE tmt*outcome / relrisk ;
Weight freq ;
run ;
The output is shown below.
WRONG answers! |
|
|
Odds Ratio and Relative Risks | |||
Statistic | Value | 95% Confidence Limits | |
Odds Ratio | 0.5990 | 0.1737 | 2.0649 |
Relative Risk (Column 1) | 0.9921 | 0.9736 | 1.0110 |
Relative Risk (Column 2) | 1.6563 | 0.4893 | 5.6069 |
RIGHT answer! |
|
|
Odds Ratio and Relative Risks | |||
Statistic | Value | 95% Confidence Limits | |
Odds Ratio | 0.5990 | 0.1737 | 2.0649 |
Relative Risk (Column 1) | 0.6037 | 0.1784 | 2.0437 |
Relative Risk (Column 2) | 1.0080 | 0.9891 | 1.0272 |
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.