%macro csplot(ds,entry,covs,strat,time,status,modtitle, trycov1=., plotscore=.); %if &strat=. %then; %else %do; proc sort data=&ds; by &strat; run; %end; data &ds; set &ds; idno=_n_; run; proc phreg data=&ds ; %if &strat=. %then; %else strata &strat; ; model &time*&status(0)=&covs/entry=&entry; id idno %if &trycov1=. %then; %else &trycov1 ; %if &strat=. %then; %else &strat ; ; baseline out=anderson logsurv=ls/method=emp; output out=residds resmart=resmart resdev=resdev dfbeta=db1 ressco=sc1; run; /********************************************************/ /* Use resmart to get csresid rather than estimated haz-*/ /* zard because it's still OK for delayed entry. */ /********************************************************/ data residds; set residds; csresid=status-resmart; run; title2 'Model '&modtitle; %coxsnell(status); %if &trycov1=. %then; %else %do; title3 'Martingale Residuals'; proc gplot data=residds; plot resmart*&trycov1; run; title3 'Deviance Residuals'; proc gplot data=residds; plot resdev*&trycov1; run; quit; %end; %if &plotscore=. %then; %else %do; title3 'Score Residuals'; proc gplot data=residds; plot sc1*&time; run; quit; title3 'Influence Function'; proc gplot data=residds; plot db1*idno; run; quit; %end; %if &strat=. %then; %else %do; title3 'Anderson plots'; proc sort data=anderson; by time; run; /* Do Anderson plots assuming strata are coded 0 and 1 */ data anderson; set anderson; retain h0 h1; h=log(-ls); if &strat=0 then h0=h; else h1=h; run; proc gplot data=anderson; plot h1*h0; run; quit; %end; %mend; %macro coxsnell(status); proc phreg data=residds noprint; model csresid*&status(0)=; baseline out=outdat logsurv=haz/method=emp; run; data outdat; set outdat; haz=-haz ; run; title3 'Cox and Snell Residuals'; proc gplot data=outdat; symbol1 i=stepjl line=1 color=black; symbol2 i=join line=2 color=black; plot haz*csresid=1 haz*haz=2/overlay; run; quit; symbol1 i=none v=plus; %mend;