%macro powerRxC( version, data=_last_, /* input data set */ row=, /* the row variable - REQUIRED */ col=, /* the column variable - REQUIRED */ count=, /* the variable of frequency counts, if the input data are cell counts of a table */ level=.05, /* the level of the test */ nrange= /* the sample size or range of sample sizes for which power is desired. If not specified, the actual sample size is used. Examples: nrange=20 to 200 by 20 nrange=%str(20,50,100,140) nrange=%str(20, 50 to 100 by 10) Note that %STR() should be used when commas appear in your range specification. */ ); %if &version ne %then %put POWERRxC macro Version 1.1; %let notesopt = %sysfunc(getoption(notes)); options nonotes; %let lastds=&syslast; %if %bquote(&row)= %then %do; %put ERROR: The ROW= argument must be specified.; %goto exit; %end; %if %bquote(&col)= %then %do; %put ERROR: The COL= argument must be specified.; %goto exit; %end; proc freq data=&data; %if %bquote(&count) ne %then weight &count%str(;); tables &row * &col / chisq out=_cells; output out=_chi pchi lrchi; run; data _power; merge _cells _chi; if _n_=2 then stop; sampsize=100*count/percent; do n= %if %bquote(&nrange)= %then sampsize; %else &nrange; ; powerp =1-probchi(cinv(1-&level,df_pchi),df_pchi,_pchi_*n/sampsize); powerlr=1-probchi(cinv(1-&level,df_lrchi),df_lrchi,_lrchi_*n/sampsize); keep n powerp powerlr; output; end; run; proc print noobs split='/'; label powerp ="Power of/Pearson/Chi-square" powerlr="Power/of L.R./Chi-square"; title "Approximate Power of Chi-square Tests for Independence"; title2 "Test Level=&level"; run; title; %exit:; options ¬esopt _last_=&lastds; title; %mend powerRxC;