|
|
8#

楼主 |
发表于 2005-11-10 23:34:57
|
只看该作者
Re:
将ods与tabulate结合起来使用就可以满足一般的表格制作需要了,我做了很多的统计分析,均是这么做的,此外,还可以自己编制宏程序也可以解决这个问题。下面给出一段程序,请各位指教。
[code:645a5]%MACRO meanf2(data,var=,colvar=,rowvar=,dec=0.1,prnopt=0,where=);
*****************************************************************
stratified calculation of N MEAN STD
Example:
%unistrat(workdata, * dataset name
var=height weight bsfev1 b1fev1, * variables name
colvar=sex, * column strata variable name
rowvar=nid mech smk_cur, * row strata variables name
dec=0.1); * decimal posiong
*******************************************************************;
options nocenter nodate nonumber;title;
%let nrv=%wordcnt(string=&rowvar, delim=%str( ));
%let nxv=%wordcnt(string=&var, delim=%str( ));
PROC IML;USE &data;SETIN &data;reset noname nocenter;
dcm=abs(log10(&dec));dct=dcm+5;xvar={&var}`;xvar=compress(xvar);
Start meanxx(mx);
dcm=abs(log10(&dec));dct=dcm+5;
nmx=choose(mx=.,0,1)[+,];meanx=mx[+,]/nmx;
stdx=(((mx#mx)[+,]-mx[+,]#mx[+,]/nmx)/(nmx-1))##0.5;
return
(compress(char(meanx,dct,dcm)+"+"+char(stdx,dct,dcm)+", ("+char(nmx,5)+")"));
Finish meanxx;
read all var {&var} into DD1 %if &where ^= %then where (&where);;
%if &colvar^= %then %do;
read all var {&colvar} into CC %if &where ^= %then where (&where);;
%end; %else %do; CC=j(nrow(DD),1,1); %end;
CC1=unique(CC);CC2=CC1[,loc(CC1^=.)];nccv=ncol(CC2);
%if &colvar^= %then
clname="Var. Strata"||compress("&colvar"+"="+char(CC2));
%else clname=" ";;
%do x=1 %to &nxv; DD=DD1[,&x]; xvi=xvar[&x];
%do r=1 %to &nrv;
%let rvi=%scan(&rowvar, &r);
read all var {&rvi} into RR %if &where ^= %then where (&where);;
RR1=unique(RR);
if type(RR)='N' then RR1=RR1[,loc(RR1^=.)];
else RR1=RR1[,loc(RR1>" ")];
nrrv=ncol(RR1);
do b=1 to nrrv;
rrb=RR1[b];if type(rrb)='N' then rrb1=compress(char(rrb));
rrbc=xvi+": "+"&rvi="+rrb1;
do c=1 to nccv; ccc=CC2[c];
LL1=choose(CC=ccc,1,0);LL2=choose(RR=rrb,1,0);LL=choose(LL1=LL2,LL1,0);
if type(ccc)='N' then ccc1=char(ccc);
if sum(LL)>3 then OO=OO||meanxx(DD[loc(LL=1),]);
else OO=OO||j(1,ncol(DD)," ");
end;
OOR=OOR//(rrbc||shape(OO,1));free OO;
end;
%end;
%end;
*OXI=(compress(OOR[,1])+"="+compress(OOR[,2]))||OOR[,3:(ncol(OOR))];
print "Mean+SD(N) for &var,data:&data &where",OOR [colname=clname];
free OOR;
QUIT;
%if &prnopt=0 %then %do;ods select none;%end;
%do x=1 %to &nxv; %let xvi=%scan(&var,&x);
%do r=1 %to &nrv;
%let rvi=%scan(&rowvar,&r);
proc glm data=&data;where &where;class &rvi &colvar;
ods output modelanova=tmp1;
model &xvi=&rvi &colvar %if &colvar ne %then %do;&rvi*&colvar;%end;;
run;
%if &r=1 and &x=1 %then %do; data tmpaov;set tmp1;run;%end;
%else %do; data tmpaov;set tmpaov tmp1;memo=" ";
if 0<probf<=0.01 then memo="**";
else if 0.01<probf<=0.05 then memo="*";
else if 0.05<probf<=0.10 then memo="@";run;%end;
%end;
%end;
ods select all;
proc print data=tmpaov noobs;var dependent source df ss fvalue probf memo;
data tmp1;data tmpaov;run;
%MEND meanf2;[/code:645a5]具体的用法:
%meanf2(aa,colvar=group,rowvar=sex smoke,var=sbp dbp,dec=0.01);
搞定 |
|