%macro survci(ds,tm,state,tp,byvar); /***********************************************************/ /* Macro does separate Kaplan Meier plots, with confidence */ /* limits on log or original scale, and then performs log */ /* rank test. Macro parameters: data set name, name of time*/ /* variable, name of censoring variable, the word normal or*/ /* log, and name of categorical variable splitting data set*/ /* into groups to be treated separately. */ /* First task is to sort the data by group to be tested. */ /***********************************************************/ %if &byvar=none %then ; %else %do; proc sort data=&ds; by &byvar; run; %end; proc lifetest data=&ds nocens notable;time &tm*&state(0); %if &byvar=none %then ; %else %do; test &byvar; %end; run; /***********************************************************/ /* phreg is a black box (for now) generating Kaplan Meier */ /* along with CIS on various scales. */ /***********************************************************/ proc phreg data=&ds noprint; model &tm*&state(0)=; %if &byvar=none %then ; %else %do; by &byvar; %end; baseline out=pltdat survival=s u=u l=l/cltype=&tp; run; /***********************************************************/ /* Output upper and lower bounds, and estimate, onto */ /* separate lines. Create variable newby having a */ /* different value for each line we need to plot. For ex, */ /* with two groups you need 3*2 lines, and so newby has 6 */ /* distinct values. Also, make vertical axis say Survival.*/ /***********************************************************/ data newplot; set pltdat; a=s; b=1; output; a=l; b=2; output; a=u; b=3; output; run; data newplot; set newplot; newby=&byvar||b ; run; axis2 label=(a=90 'Survival' ); /***********************************************************/ /* SAS allows users to determine the style for each set of */ /* points it plots. I want a solid line for each KM */ /* estimate and a dashed line for confidence bounds, and I */ /* want a stair-step pattern. Inside the macro I don't */ /* have convenient access to a variable telling me how many*/ /* groups I have, and so I set up 33, more than I need. */ /***********************************************************/ %do i=1 %to 33; %do l=1 %to 3; %let j=%eval(3*(&i-1)+&l); symbol&j i=stepjl line= &l color=black; %end;%end; proc gplot data=newplot; plot a*&tm=newby /vaxis=axis2; run; quit; %mend;