Customizing the Kaplan-Meier Survival Plot


The Macro Variables

The macros and macro variables are designed so that most of the time you need to modify only the macro variables and not the larger macros. However, you have the full flexibility to modify both. You can modify any of the following macro variables:

%let TitleText0 = METHOD " Survival Estimate";
%let TitleText1 = &titletext0 " for " STRATUMID;
%let TitleText2 = &titletext0 "s";         /* plural: Survival Estimates */
%let nTitles    = 2;

%let yOptions   = label="Survival Probability" shortlabel="Survival"
                  linearopts=(viewmin=0 viewmax=1
                              tickvaluelist=(0 .2 .4 .6 .8 1.0));

%let xOptions   = shortlabel=XNAME offsetmin=.05
                  linearopts=(viewmax=MAXTIME tickvaluelist=XTICKVALS
                              tickvaluefitpolicy=XTICKVALFITPOL);

%let Tips       = rolename=(_tip1= ATRISK _tip2=EVENT)
                  tiplabel=(_tip1="Number at Risk" _tip2="Observed Events")
                  tip=(x y _tip1 _tip2);
%let TipLabel   = tiplabel=(y="Survival Probability");
%let StepOpts   = ;

%let Groups     = group=STRATUM index=STRATUMNUM;

%let BandOpts   = displayTail=false &groups modelname="Survival";

%let InsetOpts  = autoalign=(TOPRIGHT BOTTOMLEFT TOP BOTTOM)
                  border=true BackgroundColor=GraphWalls:Color Opaque=true;
%let LegendOpts = title=GROUPNAME location=outside;

%let AtRiskOpts = display=(label) valueattrs=(size=7pt);
%let ClassOpts  = class=CLASSATRISK colorgroup=CLASSATRISK;

%let Censored   = markerattrs=(symbol=plus);
%let CensorStr  = "+ Censored";

%let GraphOpts  = ;

The %ProvideSurvivalMacros macro declares that these macro variables are global in scope, so you can assign values to them in your programs and have them affect the internal macros. These macro variables specify a variety of GTL options; for more information, see SAS Graph Template Language: Reference. The macro variables are as follows.

TitleText0

provides the common text that is used in the title for the single-stratum and multiple-strata cases. METHOD is a dynamic variable that PROC LIFETEST sets. In these examples, the value of METHOD is 'Product-Limit'; the product-limit method is also known as the Kaplan-Meier (1958) method.

TitleText1

provides the title text for the single-stratum title (relying on TitleText0).

TitleText2

provides the title text for the multiple-strata title (relying on TitleText0).

nTitles

specifies the number of titles. Set the macro variable nTitles to 1 to suppress the second title line or 0 to suppress all title lines. You can add titles to the plot by adding ENTRYTITLE statements to the top of the %StmtsBeginGraph macro even when you suppress the usual titles by setting the nTitles macro variable to 0 or 1. By default, nTitles equals 2.

yOptions

provides the Y-axis options. The LABEL= option provides the axis label. The SHORTLABEL= option provides the axis label for small plots when the LABEL= option label is too long. The LINEAROPTS= option specifies linear axis options. This and most other axes are linear axes; alternatives include log-scale axes. The VIEWMIN=0 and VIEWMAX=1 options ensure that the axis goes from 0 to 1 even when the actual results have a more restricted range. The TICKVALUELIST= option provides the tick values. Standard SAS number list abbreviations like 0 TO 1 BY 0.2 are not valid in the GTL.

xOptions

provides the X-axis options. The LABEL= option is not provided, so the axis label comes from the column label in the ODS data object. You can add a LABEL= option or other axis options if you want. The SHORTLABEL= option provides the axis label for small plots when the label is too long. The short label comes from a dynamic variable that PROC LIFETEST provides. The OFFSETMIN= option ensures that there is extra space between the axis and the minimum tick mark. The LINEAROPTS= option specifies linear axis options. The VIEWMAX= option ensures that the axis goes to the value in the MAXTIME dynamic variable set by PROC LIFETEST. The TICKVALUELIST= option provides the tick values in a dynamic variable. The TICKVALUEFITPOLICY= option provides, in a dynamic variable, the approach for handling dense tick marks. Approaches include rotation, staggering, and thinning.

Tips

provides options for tooltips for the step plots. Tooltips are text boxes that appear in HTML output when you rest your mouse pointer over part of the plot when the IMAGEMAP=ON option is specified in the ODS GRAPHICS statement. Tooltips are provided for the X- and Y-axis columns. Additional columns that are assigned roles (and hence are eligible to use as tooltips) include the at-risk and event columns. These columns are given the tooltip labels 'Number at Risk' and 'Observed Events'. Unless you are specifically interested in tooltips, you probably do not need to modify this macro variable.

TipLabel

provides a label for the Y-axis tooltip. Unless you are specifically interested in tooltips, you do not need to modify this macro variable.

StepOpts

provides options for the step functions. This macro variable is null by default. You can use this option to control the line thickness (for example, LINEATTRS=(THICKNESS=2.5)) and other aspects of the step functions.

Groups

provides the name of the data object columns that provide group names and the index that provides the order of the group names. You will probably never need to modify this macro variable.

BandOpts

provides the group information for band plots. You will probably never need to modify this macro variable.

InsetOpts

provides options for the inset table that provides the censored value legend and the homogeneity test p-value. The AUTOALIGN= option specifies the places in the plot where the inset table can be positioned. If your preferred placement is somewhere other than the top right corner, you can modify the automatic placement list. The BORDER= option displays a border around this table. The BACKGROUNDCOLOR= option controls the table background. By default, it matches the background color for the rest of the plot by using the GraphWalls:Color style reference. The OPAQUE=TRUE option specifies an opaque table that hides any graphical elements that are behind the table. You can set the InsetOpts macro variable to null to suppress the usual inset that contains the censored value and p-value.

LegendOpts

provides options for the external legend that identifies the strata. The title comes from a dynamic variable GroupName that the procedure sets. By default, the legend is outside the plot. Specify LOCATION=INSIDE and an AUTOALIGN= option such as the one provided in the InsetOpts macro variable if you want the legend to appear inside the plot. You can set the LegendOpts macro variable to null to suppress the legend.

AtRiskOpts

provides options for the at-risk table. The option DISPLAY=(LABEL) limits the display to labels. VALUEATTRS=(SIZE=7PT) specifies a font size of seven points.

ClassOpts

provides the options that are used in the at-risk table to distinguish groups of observations.

Censored

provides the marker (a plus sign) that is displayed in the plot to indicate censored observations.

CensorStr

provides the character for the inset table that shows how censored observations appear in the plot.

GraphOpts

provides options for the template BEGINGRAPH statement. By default, the GraphOpts macro variable is null. The following options are particularly useful:

  • ATTRPRIORITY=AUTO | NONE | COLOR specifies the priority for varying the attributes that distinguish groups of observations. AUTO honors the setting that is otherwise in effect. COLOR varies only the color attribute. NONE simultaneously varies colors, markers, and lines. Styles such as HMTLBlue and Pearl are ATTRPRIORITY=COLOR styles, whereas styles such as DEFAULT, Statistical, Listing, and RTF are ATTRPRIORITY=NONE styles.

  • DATACOLORS=(color-list)  specifies the list of colors (which control confidence bands) to replace the graph data colors from the GraphData1–GraphDataN style elements.

  • DATACONTRASTCOLORS=(color-list)  specifies the list of contrast colors (which control markers and lines) to replace the graph data contrast colors from the GraphData1–GraphDataN style elements.

  • DATALINEPATTERNS=(line-pattern-list)  specifies the list of line patterns to replace the graph data line patterns from the GraphData1–GraphDataN style elements. There are 46 line patterns, and you can specify each pattern by using an integer in the range 1 to 46. Some patterns have names associated with them. You can specify either the name or the number for the following number/name pairs: 1 Solid, 2 ShortDash, 4 MediumDash, 5 LongDash, 8 MediumDashShortDash, 14 DashDashDot, 15 DashDotDot, 20 Dash, 26 LongDashShortDash, 34 Dot, 35 ThinDot, 41 ShortDashDot, and 42 MediumDashDotDot.

  • DESIGNHEIGHT=height sets the graph height. You can set the graph height to the default graph width of 640 pixels by specifying the option DESIGNHEIGHT=DEFAULTDESIGNWIDTH. Or you can specify a size in pixels, such as DESIGNHEIGHT=500PX. Although the graph is designed at the specified height, you can resize it for the actual display by using the WIDTH= and HEIGHT= options in the ODS GRAPHICS statement. By default, DESIGNHEIGHT=480PX.

  • DESIGNWIDTH=width sets the graph width. You can set the graph width to the default graph height of 480 pixels by specifying the option DESIGNWIDTH=DEFAULTDESIGNHEIGHT. Or you can specify a size in pixels, such as DESIGNWIDTH=600PX. Although the graph is designed at the specified width, you can resize it for the actual display by using the WIDTH= and HEIGHT= options in the ODS GRAPHICS statement. By default, DESIGNWIDTH=640PX.