/************************************************************************/ /* */ /* */ /* This macro computes the direct adjusted cumulative incidence curves */ /* for K treatment groups, based on a proportional subdistribution */ /* hazards model. Please note that the hazards ratio between any two */ /* treatments is assumed to be a constant. */ /* */ /* 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; eidx=j(numtime,1,0); do i=1 to numtime; do j=1 to numobs10 until(time10[j]=etime[i]); end; eidx[i]=j; end; b=best; numdeath=j(numtime,1,0); covsum=j(numtime,&tcov,0); do i=1 to numtime; do j=1 to numobs10; if time10[j]=etime[i] & cause10[j]=1 then do; numdeath[i] = numdeath[i] + 1; covsum[i,] = covsum[i,] + z10[j,]; end; end; end; incre=1; do iter=1 to 20 until(incre<.0005); s0_1=j(numtime,1,0); s1_1=j(numtime,&tcov,0); s2_1=j(numtime,&tnum,0); score=j(1,&tcov,0); fisher=j(&tcov,&tcov,0); loglike=0; expbz10=j(numobs10,1,0); do i=1 to numobs10; expbz10[i]=b*t(z10[i,]); end; expbz10=exp(expbz10); expbz2=j(numobs2,1,0); do i=1 to numobs2; expbz2[i]=b*t(z2[i,]); end; expbz2=exp(expbz2); pres0=0; pres1=j(1,&tcov,0); pres2=j(1,&tnum,0); obsidx=numobs10; do i=numtime to 1 by -1; s0_1[i]=pres0; s1_1[i,]=pres1; s2_1[i,]=pres2; do j=eidx[i] to obsidx; s0_1[i] = s0_1[i] + expbz10[j]; s1_1[i,] = s1_1[i,] + z10[j,]#expbz10[j]; tonext=1; do m=1 to &tcov; do n=m to &tcov; s2_1[i,tonext] = s2_1[i,tonext] + z10[j,m]#z10[j,n]#expbz10[j]; tonext = tonext + 1; end; end; end; pres0=s0_1[i]; pres1=s1_1[i,]; pres2=s2_1[i,]; obsidx=eidx[i]-1; end; s0_2=j(numtime,1,0); s1_2=j(numtime,&tcov,0); s2_2=j(numtime,&tnum,0); do i=1 to numtime; do j=1 to numobs2; cweight=eckm[i]/ckm2[j]; weight=min(1,cweight); s0_2[i] = s0_2[i] + expbz2[j]#weight; s1_2[i,] = s1_2[i,] + z2[j,]#expbz2[j]#weight; tonext=1; do m=1 to &tcov; do n=m to &tcov; s2_2[i,tonext] = s2_2[i,tonext] + z2[j,m]#z2[j,n]#expbz2[j]#weight; tonext = tonext + 1; end; end; end; end; s0=s0_1+s0_2; s1=s1_1+s1_2; s2=s2_1+s2_2; do i=1 to numtime; score = score + covsum[i,] - s1[i,]#(numdeath[i]/s0[i]); tonext=1; do m=1 to &tcov; do n=m to &tcov; fisher[m,n] = fisher[m,n] + s2[i,tonext]#(numdeath[i]/s0[i]) - s1[i,m]#s1[i,n]#(numdeath[i]/s0[i]##2); tonext = tonext + 1; end; end; loglike = loglike + b*t(covsum[i,])-numdeath[i]*log(s0[i]); end; do m=2 to &tcov; 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; do i=1 to numobs10; expbz10[i]=b*t(z10[i,]); end; expbz10=exp(expbz10); do i=1 to numobs2; expbz2[i]=b*t(z2[i,]); end; expbz2=exp(expbz2); lambda1=j(numtime,1,0); dlambda1=j(numtime,1,0); ltemp=0; do i=1 to numtime; dlambda1[i]=numdeath[i]/s0[i]; ltemp=ltemp+dlambda1[i]; lambda1[i]=ltemp; end; eta_1=j(numobs10,&tcov,0); dmart1_1=j(numobs10,numtime,0); do i=1 to numobs10; do j=1 to numtime; if time10[i]>=etime[j] then dmart1_1[i,j]=-dlambda1[j]#expbz10[i]; if cause10[i]=1 & time10[i]=etime[j] then dmart1_1[i,j]=dmart1_1[i,j]+1; eta_1[i,] = eta_1[i,] + (z10[i,]-s1[j,]/s0[j])*dmart1_1[i,j]; end; end; eta_2=j(numobs2,&tcov,0); dmart1_2=j(numobs2,numtime,0); do i=1 to numobs2; do j=1 to numtime; cweight=eckm[j]/ckm2[i]; weight=min(1,cweight); dmart1_2[i,j]=-dlambda1[j]#expbz2[i]#weight; eta_2[i,] = eta_2[i,] + (z2[i,]-s1[j,]/s0[j])*dmart1_2[i,j]; end; end; numobs=numobs10+numobs2; dmart1=dmart1_1//dmart1_2; time=time10//time2; cause=cause10//cause2; zmat=z10//z2; eta=eta_1//eta_2; psi=j(numobs,&tcov,0); q=j(numctime,&tcov,0); do i=1 to numctime while (cidx[i]>0); do j=1 to numobs2 while (ctime[i]>time2[j]); do k=cidx[i] to numtime; q[i,]=q[i,]+(z2[j,]-s1[k,]/s0[k])#dmart1_2[j,k]; 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(&tcov,&tcov,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(&tcov,1,0); do i=1 to &tcov; se[i]=sqrt(robustv[i,i]); end; bout=t(b)||se; hazout=etime||lambda1; create best from bout[colname={'Estimate' 'SE'}]; append from bout; close best; names={%do i=2 %to &numgroup; "G&i" %end; %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' 'Base_haz'}]; append from hazout; close basehaz; vut=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 numobs2; if time2[k]