程序为(错误部分标红)
proc IML;
use all;
read all var {_Ni_} into allN;
read all var {variance} into variance;
close all;
/** read in all RRs and save as matrix R **/
use noRef;
read all var {rr} into R;
read all var {_Ni_} into N;
read all var {_Ai_} into initialA;
read all var {study} into study;
read all var{dose} into dose;
read all var {type} into stype;
close noRef;
/** read in the sums of subjects for reference level **/
use refN;
read all var {_Ni_} into N0;
close refN;
/** read in the sums of cases and subjects for each study **/
use mout;
read all var {sumA p studyNum} into T;
close mout;
/** define function f for cohort study **/
start f(A) global (N01, M, N1, R1);
A = t(A);
temp=(N01/(M-A[+])) # (A/N1)-R1; *risk ratio?;
return (temp);
finish;
/** define function g for case control study **/
start g(A) global (N01, M, N1, R1);
A = t(A);
temp=(N01/(M-A[+])-1) # (A/(N1-A))-R1;
return (temp);
finish;
sump=0;
sump2=0;
part1=0;
part2=0;
do s=1 to nrow(T); *loop for each study;
N01=N0
M=T[s,1]; *total number of cases in all groups;
p=T[s,2];
study_s=T[s,3];
*actual name;
stu=study[sump+1];
N1=N[(sump+1):(sump+p),]; * # of subjects in each group;
R1=R[(sump+1):(sump+p),]; * rr in each group;
startA=initialA[(sump+1):(sump+p),]; * initial values=actual values;
allN1=allN[(sump2+1):(sump2+p+1),]; * total N for all groups;
variance1=variance[(sump2+1):(sump2+p+1),];
dose1=dose[(sump+1):(sump+p),]; * include spline variables;
type=stype[sump+1,1];
optn=p;
C=J(p,p,0);
cor=J(p,p,1);
/** 1. cohort with person time **/
if type=1 then do;
call nlplm(rc, root, "f", startA, optn);
A0=M-t(root)[+]; *estimated cell # for reference group;
ahat=t(A0||root); *estimated cell #s for all groups;
* print ahat A0 N01 allN1;
rrhat=(ahat/allN1)/(A0/N01);
s2=1/ahat+1/A0;
do i=1 to p;
do j=1 to p;
if i=j then do;
C[i,j]=variance1[i+1]; end;
else do;
cor[i,j]=(1/A0)/sqrt((1/root+1/A0)*(1/root[j]+1/A0));
C[i,j]= cor[i,j]*sqrt(variance1[i+1]*variance1[j+1]);
end;
end;
end;
end;
/** 2. cohort study with total observation instead of person time **/
else if type=2 then do;
call nlplm(rc, root, "f", startA, optn);
A0=M-t(root)[+]; *estimated cell # for reference group;
ahat=t(A0||root); *estimated cell #s for all groups;
rrhat=(ahat/allN1)/(A0/N01);
s2=1/ahat-1/allN1 + 1/A0 -1/N01;
se=sqrt(s2);
do i=1 to p;
do j=1 to p;
if i=j then C[i,j]=variance1[i+1];
else do;
cor[i,j]=(1/A0-1/N01)/(se[i+1]*se[j+1]);
C[i,j]=cor[i,j]*(sqrt(variance1[i+1]*variance1[j+1]));
end;
end;
end;
end;
/** 3. case-control study **/
else if type=3 then do;
call nlplm(rc, root, "g", startA, optn);
A0=M-t(root)[+]; *estimated cell # for reference group;
ahat=t(A0||root); *estimated cell #s for all groups;
riskhat0=A0/(N01-A0);
riskhat=ahat/(allN1-ahat);
rrhat=riskhat/riskhat0;
s2=1/A0+1/(N01-A0)+1/ahat+1/(allN1-ahat);
se=sqrt(s2);
do i=1 to p;
do j=1 to p;
if i=j then C[i,j]=variance1[i+1];
else do;
cor[i,j]=(1/A0+1/(N01-A0))/(se[i+1]*se[j+1]);
C[i,j]=cor[i,j]*(sqrt(variance1[i+1]*variance1[j+1]));
end;
end;
end;
end;
k=1;
lowerC=J(p*(p+1)/2, 1,.);
do i=1 to p;
do j=1 to i;
lowerC[k]=C[i,j];
k=k+1;
end;
end;
vbstar=inv(t(dose1)*inv(C)*dose1);
sestar=sqrt(vbstar);
bstar=vbstar*t(dose1)*inv(C)*log(R1);
GreenlandRR=exp(1*bstar);
GreenlandUB=exp(1*(bstar+1.96*sqrt(vbstar)));
GreenlandLB=exp(1*(bstar-1.96*sqrt(vbstar)));
tmp=tmp//(ahat||rrhat||s2);
tmp2=tmp2//(study_s||bstar|| sestar||GreenlandRR|| GreenlandLB|| GreenlandUB);
lowerVar=lowerVar//(J(p*(p+1)/2,1,study_s)||lowerC);
sumP=sump+p;
sump2=sump2+p+1;
/** go back to the next study **/
end; /** end of do s=1 to nrow(T) */
NOTE: ABSGCONV convergence criterion satisfied.
NOTE: ABSGCONV convergence criterion satisfied.
NOTE: ABSGCONV convergence criterion satisfied.
ERROR: (execution) Invalid argument to function.
operation : SQRT at line 3306 column 15
operands : vbstar
vbstar 1 row 1 col (numeric)
-3.621E-7
statement : ASSIGN at line 3306 column 4
create g_ahat from tmp [colname={Greenland_Est_A rrhat greenVar}];
append from tmp;
create Greenland from tmp2 [colname={studyNum g_bstar g_sestar g_RRstar g_LBstar g_UBstar}];
append from tmp2;
create lowerVar from lowerVar[colname={study var}];
append from lowerVar;
free /;
quit;
run;



雷达卡


京公网安备 11010802022788号







