各位大神,我从网上找了个卡方两两比较的SAS程序,但是只能比较到2和3,我的是7个组,求帮忙看一下程序哪里有问题,谢谢!
/* libname:The libname of your dataset */
/* filename:The name of your dataset */
/* fvar: The WEIGHT variable */
/* gvar: The variable for grouping */
/* outcomevar: The outcome variable*/
%macro multicompare(libname=,filename=,fvar=,gvar=,outcomevar=);
options nodate nonumber formdlim='*';
title;
/*Conduct Chi-sqare test for comparison of all groups*/
proc freq data=test;
tables &gvar*&outcomevar / nocol norow nopercent chisq;
weight f;
run;
/*Create symbols to distinguish different subgroups*/
proc sql noprint;
select n(distinct &gvar) into :gn from &libname..&filename.;
select distinct a.&gvar,b.&gvar into :ag separated by '-',:bg separated by '-'
from &libname..&filename. a,&libname..&filename. b where a.&gvar<b.&gvar;
quit;
%let gn1=%eval(&gn);
/*Combine subgroups*/
%Macro chisq;
%do t=1 %to &gn1;
%let m=%scan(&ag,&t);
%let n=%scan(&bg,&t);
proc sql ;
create table test as select * from &libname..&filename. where &gvar=&m or &gvar=&n;
quit;
/*Conduct Chi-sqare test for multicomparison of subgroups*/
proc freq data=test;
tables &gvar*&outcomevar / nocol norow nopercent chisq;
weight f;
run;
/*Calculate the adjusted alpha*/
data alpha;
alpha=0.05/(&gn1*(&gn1-1)/2+1);
proc print data=alpha;
run;
%end;
%mend chisq;
%chisq;
%mend multicompare;
data a;
do group=1 to 7;
do factor=1 to 2;
input f @@;output;
end;
end;
cards;
6 36 9 11 17 18 19 31 15 6 7 7 9 14
;
run;
%multicompare(libname=work,filename=a,fvar=f,gvar=group,outcomevar=factor);