/* chisquare_2way1.sas */ /* chisquare tests: homogeneity and independence */ /* ------------------------------------------- */ /* chisquare test of homogeneity */ /* ------------------------------------------- */ data cocaine; input treat $ relapse $ count; cards; desip no 14 desip yes 10 lithium no 6 lithium yes 18 ; proc freq data=cocaine; tables treat*relapse / nocol nocum nopercent chisq cellchi2 deviation expected; weight count; title 'cocaine treatment'; run; /* ------------------------------------------- */ data attitude; input group $ attitude $ count; cards; rural athletic 42 rural grades 57 rural popular 50 suburb athletic 22 suburb grades 87 suburb popular 42 urban athletic 26 urban grades 103 urban popular 49 ; proc freq data=attitude; tables group*attitude / nocol nocum nopercent chisq cellchi2 deviation expected; weight count; title 'student attitudes'; run; /* ------------------------------------------- */ /* chi-square test of independence */ /* ------------------------------------------- */ data blood; input group $ type $ count; cards; H A 2490 HC A 2368 HW A 4671 W A 50008 H AB 99 HC AB 243 HW AB 236 W AB 5001 H B 178 HC B 568 HW B 606 W B 16252 H O 1903 HC O 2206 HW O 4469 W O 53759 ; proc freq data=blood; tables type*group / chisq cellchi2 expected; weight count; title 'blood types'; run;