Customizing the Kaplan-Meier Survival Plot


Adding a Small Inset Table with Event Information

This example shows you how to modify the template to produce the plot displayed in Figure 23.29. This new plot has an inset table in the top right corner that shows the number of observations and the number of events in each stratum. The legend has been moved inside the plot and combined with the old inset table that shows the marker for censored observations.[18] Also, the title is changed to 'Kaplan-Meier Plot'.

%ProvideSurvivalMacros

%let TitleText2 = "Kaplan-Meier Plot";
%let LegendOpts = title="+ Censored"
                  location=inside autoalign=(Bottom);
%let InsetOpts  = ;

%macro StmtsBottom;
   dynamic %do i = 1 %to 3; StrVal&i NObs&i NEvent&i %end;;
   layout gridded / columns=3 border=TRUE autoalign=(TopRight);
      entry ""; entry "Event"; entry "Total";
      %do i = 1 %to 3;
         %let t = / textattrs=GraphData&i;
         entry halign=right Strval&i &t; entry NEvent&i &t; entry NObs&i &t;
      %end;
   endlayout;
%mend;

%CompileSurvivalTemplates

proc lifetest data=sashelp.BMT plots=survival(cb=hw atrisk(outside maxlen=13));
   time T * Status(0);
   strata Group;
run;

The results are displayed in Figure 23.29.

Figure 23.29: New Inset Table with Event Information

New Inset Table with Event Information


The macro variable TitleText2, which controls the title for the multiple-strata plot, is changed. You can change all three title macro variables, as is done in the construction of Figure 23.17, or you can change only TitleText2 when you have multiple overlaid strata, as in this example. The LegendOpts macro variable value was changed from TITLE=GROUPNAME LOCATION=OUTSIDE to display the censored value legend in place of the legend title and to display the legend inside the bottom of the plot. When the InsetOpts macro variable is null, the usual inset that contains the censored value and p-value is not displayed.

The %StmtsBottom macro (null by default) is replaced with a macro that creates the new inset table. This macro adds statements to the bottom of the templates. If you ignore for a moment most of the options, the core of the generated statements is as follows:

dynamic StrVal1 NObs1 NEvent1 StrVal2 NObs2 NEvent2 StrVal3 NObs3 NEvent3;
layout gridded / columns=3;
   entry "";        entry "Event";   entry "Total";
   entry Strval1;   entry NEvent1;   entry NObs1;
   entry Strval2;   entry NEvent2;   entry NObs2;
   entry Strval3;   entry NEvent3;   entry NObs3;
endlayout;

The macro first constructs a DYNAMIC statement that includes the names of the dynamic variables that contain some of the results. PROC LIFETEST creates these dynamic variables and sets them to values, but you must declare them in your template before using them. For more information about these dynamic variables, see the section Additional Dynamic Variables. The macro then constructs a 4 $\times $ 3 grid that contains a table consisting of a title line and a row for each stratum (which consists of the stratum label, the number of events, and the total number of subjects). The full layout that the %StmtsBottom macro generates, with all the options, is as follows:

dynamic StrVal1 NObs1 NEvent1 StrVal2 NObs2 NEvent2 StrVal3 NObs3 NEvent3;
layout gridded / columns=3 border=TRUE autoalign=(TopRight);
   entry "";
   entry "Event";
   entry "Total";
   entry halign=right Strval1 / textattrs=GraphData1;
   entry NEvent1 / textattrs=GraphData1;
   entry NObs1 / textattrs=GraphData1;
   entry halign=right Strval2 / textattrs=GraphData2;
   entry NEvent2 / textattrs=GraphData2;
   entry NObs2 / textattrs=GraphData2;
   entry halign=right Strval3 / textattrs=GraphData3;
   entry NEvent3 / textattrs=GraphData3;
   entry NObs3 / textattrs=GraphData3;
endlayout;


[18] This legend is wide and might not be displayed if your graph is small. If the legend is not displayed, try increasing the size of the graph by specifying the WIDTH= or HEIGHT= option in the ODS GRAPHICS statement.