/************************************************************************/ /* */ /* */ /* This macro computes the direct adjusted cumulative incidence curves */ /* for K treatment groups, based on a proportional subdistribution */ /* hazards model with treatment groups as strata. */ /* */ /* Macro parameters: */ /* inputdata - the input sas data name; */ /* time - the survival time variable; */ /* event - 0 (censor) 1 (cause of interest) 2 (other causes); */ /* group - the treatment group variable, */ /* which must take values 1,...,K for K groups. */ /* covlist - a list of covariate names; */ /* outdata - the output sas data name. */ /* */ /* The output dataset contains: */ /* Time - the event times */ /* CIFi, i=1,...,K */ /* SEi, i=1,...,K */ /* SEi_j, 1<=ietime[numtime] then cidx[i]=-1; else do; do j=1 to numtime until(etime[j]>=ctime[i]); end; cidx[i]=j; end; end; %do gp=1 %to &numgroup; numdeath&gp=j(numtime,1,0); covsum&gp=j(numtime,&numcov,0); do i=1 to numtime; do j=1 to numobs&gp._10; if time&gp._10[j]=etime[i] & cause&gp._10[j]=1 then do; numdeath&gp[i] = numdeath&gp[i] + 1; covsum&gp[i,] = covsum&gp[i,] + z&gp._10[j,]; end; end; end; eidx&gp=j(numtime,1,0); do i=1 to numtime; do j=1 to numobs&gp._10 until(time&gp._10[j]>=etime[i]); end; eidx&gp[i]=j; end; %end; b=j(1,&numcov,0); b=best; incre=1; do iter=1 to 20 until(incre<.0005); score=j(1,&numcov,0); fisher=j(&numcov,&numcov,0); loglike=0; %do gp=1 %to &numgroup; s0&gp._1=j(numtime,1,0); s1&gp._1=j(numtime,&numcov,0); s2&gp._1=j(numtime,&tnum,0); expbz10=j(numobs&gp._10,1,0); do i=1 to numobs&gp._10; expbz10[i]=b*t(z&gp._10[i,]); end; expbz10=exp(expbz10); expbz2=j(numobs&gp._2,1,0); do i=1 to numobs&gp._2; expbz2[i]=b*t(z&gp._2[i,]); end; expbz2=exp(expbz2); pres0=0; pres1=j(1,&numcov,0); pres2=j(1,&tnum,0); obsidx=numobs&gp._10; do i=numtime to 1 by -1; s0&gp._1[i]=pres0; s1&gp._1[i,]=pres1; s2&gp._1[i,]=pres2; do j=eidx&gp[i] to obsidx; s0&gp._1[i] = s0&gp._1[i] + expbz10[j]; s1&gp._1[i,] = s1&gp._1[i,] + z&gp._10[j,]#expbz10[j]; tonext=1; do m=1 to &numcov; do n=m to &numcov; s2&gp._1[i,tonext] = s2&gp._1[i,tonext] + z&gp._10[j,m]#z&gp._10[j,n]#expbz10[j]; tonext = tonext + 1; end; end; end; pres0=s0&gp._1[i]; pres1=s1&gp._1[i,]; pres2=s2&gp._1[i,]; obsidx=eidx&gp[i]-1; end; s0&gp._2=j(numtime,1,0); s1&gp._2=j(numtime,&numcov,0); s2&gp._2=j(numtime,&tnum,0); do i=1 to numtime; do j=1 to numobs&gp._2; cweight=eckm[i]/ckm&gp._2[j]; weight=min(1,cweight); s0&gp._2[i] = s0&gp._2[i] + expbz2[j]#weight; s1&gp._2[i,] = s1&gp._2[i,] + z&gp._2[j,]#expbz2[j]#weight; tonext=1; do m=1 to &numcov; do n=m to &numcov; s2&gp._2[i,tonext] = s2&gp._2[i,tonext] + z&gp._2[j,m]#z&gp._2[j,n]#expbz2[j]#weight; tonext = tonext + 1; end; end; end; end; s0&gp=s0&gp._1+s0&gp._2; s1&gp=s1&gp._1+s1&gp._2; s2&gp=s2&gp._1+s2&gp._2; do i=1 to numtime; score = score + covsum&gp[i,] - s1&gp[i,]#(numdeath&gp[i]/s0&gp[i]); tonext=1; do m=1 to &numcov; do n=m to &numcov; fisher[m,n] = fisher[m,n] + s2&gp[i,tonext]#(numdeath&gp[i]/s0&gp[i]) - s1&gp[i,m]#s1&gp[i,n]#(numdeath&gp[i]/s0&gp[i]##2); tonext = tonext + 1; end; end; loglike = loglike + b*t(covsum&gp[i,])-numdeath&gp[i]*log(s0&gp[i]); end; %end; do m=2 to &numcov; do n=1 to m-1; fisher[m,n]=fisher[n,m]; end; end; oldb=b; b = b + score*inv(fisher); bchange=b-oldb; incre=max(abs(bchange)); end; hazout=etime; %do gp=1 %to &numgroup; expbz10=j(numobs&gp._10,1,0); do i=1 to numobs&gp._10; expbz10[i]=b*t(z&gp._10[i,]); end; expbz10=exp(expbz10); expbz2=j(numobs&gp._2,1,0); do i=1 to numobs&gp._2; expbz2[i]=b*t(z&gp._2[i,]); end; expbz2=exp(expbz2); lambda1&gp=j(numtime,1,0); dlambda1&gp=j(numtime,1,0); ltemp=0; do i=1 to numtime; if s0&gp[i]^=0 then do; dlambda1&gp[i]=numdeath&gp[i]/s0&gp[i]; ltemp=ltemp+dlambda1&gp[i]; end; lambda1&gp[i]=ltemp; end; eta_1=j(numobs&gp._10,&numcov,0); dmart1&gp._1=j(numobs&gp._10,numtime,0); do i=1 to numobs&gp._10; do j=1 to numtime; if time&gp._10[i]>=etime[j] then dmart1&gp._1[i,j]=-dlambda1&gp[j]#expbz10[i]; if cause&gp._10[i]=1 & time&gp._10[i]=etime[j] then dmart1&gp._1[i,j]=dmart1&gp._1[i,j]+1; eta_1[i,] = eta_1[i,] + (z&gp._10[i,]-s1&gp[j,]/s0&gp[j])*dmart1&gp._1[i,j]; end; end; eta_2=j(numobs&gp._2,&numcov,0); dmart1&gp._2=j(numobs&gp._2,numtime,0); do i=1 to numobs&gp._2; do j=1 to numtime; cweight=eckm[j]/ckm&gp._2[i]; weight=min(1,cweight); dmart1&gp._2[i,j]=-dlambda1&gp[j]#expbz2[i]#weight; eta_2[i,] = eta_2[i,] + (z&gp._2[i,]-s1&gp[j,]/s0&gp[j])*dmart1&gp._2[i,j]; end; end; eta=eta//eta_1//eta_2; dmart1=dmart1//dmart1&gp._1//dmart1&gp._2; hazout=hazout||lambda1&gp; %end; psi=j(numobs,&numcov,0); q=j(numctime,&numcov,0); do i=1 to numctime while (cidx[i]>0); %do gp=1 %to &numgroup; do j=1 to numobs&gp._2 while (ctime[i]>time&gp._2[j]); do k=cidx[i] to numtime; q[i,]=q[i,]+(z&gp._2[j,]-s1&gp[k,]/s0&gp[k])#dmart1&gp._2[j,k]; end; end; %end; q[i,]=q[i,]/pi[i]; end; dcmart=j(numobs,numctime,0); do i=1 to numobs; do j=1 to numctime; if time[i]>=ctime[j] then dcmart[i,j]=-dcna[j]; if time[i]=ctime[j] & cause[i]=0 then dcmart[i,j]=dcmart[i,j]+1; end; psi[i,]=-dcmart[i,]*q; end; sigma=j(&numcov,&numcov,0); do i=1 to numobs; sigma = sigma + t(eta[i,]+psi[i,])*(eta[i,]+psi[i,]); end; naivev = inv(fisher); robustv = inv(fisher)*sigma*inv(fisher); se=j(&numcov,1,0); do i=1 to &numcov; se[i]=sqrt(robustv[i,i]); end; bout=t(b)||se; create best from bout[colname={'Estimate' 'SE'}]; append from bout; close best; names={%do i=1 %to &numcov; "Z&i" %end;}; create covest from robustv[colname=names]; append from robustv; close covest; create basehaz from hazout[colname={'Time' %do i=1 %to &numgroup; "Base_haz&i" %end;}]; append from hazout; close basehaz; /* variance of direct adjusted CIF */ outmat=etime; %do gp=1 %to &numgroup; dacif=j(numtime,1,0); zfn1=j(numtime,1,0); zfn2=j(numtime,&numcov,0); do i=1 to numtime; do j=1 to numobs; dacif[i]=dacif[i]+1-exp(-lambda1&gp[i]#exp(b*t(zz[j,]))); zfn1[i]=zfn1[i]+exp(-lambda1&gp[i]#exp(b*t(zz[j,]))+b*t(zz[j,])); zfn2[i,]=zfn2[i,]+zz[j,]#exp(-lambda1&gp[i]#exp(b*t(zz[j,]))+b*t(zz[j,])); end; end; dacif=dacif/numobs; zfn1=zfn1/numobs; zfn2=zfn2/numobs; vut&gp=j(numctime, numtime,0); do i=1 to numctime while (cidx[i]>0); vtemp=0; do j=cidx[i] to numtime; do k=1 to numobs&gp._2; if time&gp._2[k]