/***************************************************** * Filename: m2x2.sas * Creator: Jimmy A. Doi * Date: Jan 1, 2010 * Purpose: Show X^2 and M^2 Statistics * * Macro m2x2 will compute the X^2 and M^2 statistics * and report the corresponding p-values in a convenient * format. The output will show the usual PROC FREQ * tabular display, followed by the corresponding * M^2 value and p-value, following by the corresponding * X^2 value and p-value. * * OPTIONS FORMDLIM="~"; allows for a "~~~~~~~" line to * be used between procedure outputs. This will keep all * output conveniently on one page. * * OPTIONS FORMDLIM=""; is the default behavior. This * causes one page per procedure output. This will ensure * your system is returned to default once you're done * using the code. * * This can be helpful for Problem 2.28 for the trial * and error you will be doing. * *********************************************************/ %macro m2x2; proc freq order=data; weight count ; tables Y*X; run; ods listing close; proc freq order=data; weight count ; tables Y*X/chisq; test pcorr; ods output PearsonCorr=mytable; ods output CrossTabFreqs=freqs; ods output Chisq=mychi; run; ods listing; data table; keep obs; set freqs end=last; if last then do; obs = Frequency; output; end; data select; set mytable; if Name1 = "_PCORR_" then do; r = cvalue1; output; end; data combo; keep obs r m2 pvalue; merge table select; M2 = (obs-1)*(r**2); pvalue = 1-probchi(m2,1); run; proc print data=combo;run; proc print data=mychi (obs=1); var Statistic DF Value Prob; run; %mend; data Exer_2_28; input X Y count @@; datalines; 0 0 10 0 1 10 0 2 10 1 0 10 1 1 10 1 2 10 2 0 10 2 1 10 2 2 10 ; OPTIONS FORMDLIM="~"; %m2x2; OPTIONS FORMDLIM="";