/********************************************************* SAS Textbook Examples An Introduction to Categorical Analysis by Alan Agresti Chapter 3 - Three-way Contingency Tables Inputting the Death Penalty data, table 3.1.2, p. 54. **********************************************************/; data death; input victim defendant deathp count; cards; 1 1 1 53 1 1 2 414 1 2 1 11 1 2 2 37 2 1 1 0 2 1 2 16 2 2 1 4 2 2 2 139 ; run; proc format; value defendant 1='white' 2='black'; value victim 1='white' 2='black'; value deathp 1='Yes' 2='No'; run; proc freq data = death; format defendant defendant. victim victim. deathp deathp.; weight count; by victim; table defendant*deathp / norow nocol ; exact or; run; proc freq data = death; format defendant defendant. victim victim. deathp deathp.; weight count; table defendant*deathp / norow nocol ; exact or; run; ** CMH TEST *******************************************; title "Stratified Retrospective Study: kx2x2 Table"; data ca; input gender $ ECG $ disease $ count ; cards; female <0.1 yes 4 female <0.1 no 11 female >=0.1 yes 8 female >=0.1 no 10 male <0.1 yes 9 male <0.1 no 9 male >=0.1 yes 21 male >=0.1 no 6; proc freq; weight count; tables gender*disease / nocol nopct chisq relrisk ; tables gender*ECG*disease / nocol nopct cmh chisq relrisk; tables ecg*disease / exact relrisk ; run; **********************************************************; Inputting the Chinese Smoking and Lung Cancer data, table 3.3, p. 60. data cmh; input center smoke cancer count @@; cards; 1 1 1 126 1 1 2 100 1 2 1 35 1 2 2 61 2 1 1 908 2 1 2 688 2 2 1 497 2 2 2 807 3 1 1 913 3 1 2 747 3 2 1 336 3 2 2 598 4 1 1 235 4 1 2 172 4 2 1 58 4 2 2 121 5 1 1 402 5 1 2 308 5 2 1 121 5 2 2 215 6 1 1 182 6 1 2 156 6 2 1 72 6 2 2 98 7 1 1 60 7 1 2 99 7 2 1 11 7 2 2 43 8 1 1 104 8 1 2 89 8 2 1 21 8 2 2 36 ; run; The Mantel-Haenszel odds ratio and the Breslow-Day statistic, p. 62-63. proc freq data=cmh; weight count; table center*smoke*cancer/ cmh norow nocol nopercent ; ods output RelativeRisks=temp; run; proc print data=temp (rename= (value=oddsratio) ) noobs; where studytype='Case Control (Odds Ratio)'; var center oddsratio; title 'Odds Ratio by Center'; run;