Customizing the Kaplan-Meier Plot

0

The Kaplan-Meier plot displays survival (time-to-event) data. Customizing the Kaplan-Meier plot is not a new topic. It has come up before in Graphically Speaking, SAS Communities, PharmaSUG, and elsewhere. Customizing the Kaplan-Meier plot in assorted ways is so popular that we devote an entire chapter to it in the SAS/STAT documentation. This is in addition to the chapter on PROC LIFETEST. This blog will familiarize you with that chapter. It has 36 Kaplan-Meier plots of various forms.

This link takes you to the SAS/STAT Introductory Chapters. You can click on tabs across the top to take you to documentation for different SAS releases. Starting in release 13.1 (9.4M1), you will find near the bottom of that page links for the Customizing the Kaplan-Meier Survival Plot chapter. Like every other chapter, you can view it in HTML or in PDF. (Above that chapter, you will also see three other chapters on ODS and ODS Graphics.)

The customization chapter has two major sections. The first section shows how to use procedure options to customize the graph. The second section shows you how to use macros to modify the graph template. For the 14.2 release, this link takes you to the options and this link takes you to the macros. For other releases, navigate from the tabs described above.

For every other graph, you modify the graph template in the traditional way by first accessing it (for example, by using PROC TEMPLATE and the SOURCE statement) then by editing it by using an editor or some other method such as a SAS DATA step. Then you submit it to SAS. Then you run the procedure, which uses the modified template. This might be challenging if you are not familiar with GTL. It is worth noting that when you see a graph template, you are not seeing the code as the SAS procedure writer wrote it. The template is compiled and then PROC TEMPLATE renders it. The developer might use a macro, and his or her version might be a fraction of the length of the version that you see (which does not use macros).

The Kaplan-Meier plot is different. While you can modify the Kaplan-Meier plot by using the traditional method, there is another way that works for this graph only. Only the Kaplan-Meier plot template is available to you in a series of macros and macro variables. The macros are easier to modify than the PROC TEMPLATE source. The macros are not available as SAS autocall macros, and that is deliberate. This will become clear as you work through the examples. The code is macroized in a way that enables you to modify the template by submitting as few as three lines to SAS. However, those lines do not consist of a typical macro call and arguments. The Kaplan-Meier chapter provides the following examples of template modification:

The Modularized Templates
Changing the Plot Title
Modifying the Axis
Changing the Line Thickness
Changing the Group Color
Changing the Line Pattern
Changing the Font
Changing the Legend and Inset Position
Changing How the Censored Points Are Displayed
Adding a Y-Axis Reference Line
Changing the Homogeneity Test Inset
Suppressing the Second Title and Adding a Footnote
Adding a Small Inset Table with Event Information
Adding an External Table with Event Information
Suppressing the Legend
Kaplan-Meier Plot with Event Table and Other Customizations
Compiled Template Cleanup

The examples in these sections require a onetime set up to access the macros and the macro variables. That process is described in the first section: The Modularized Templates. The chapter also provides the following examples of using options:

Enabling ODS Graphics and the Default Kaplan-Meier Plot
Individual Survival Plots
Hall-Wellner Confidence Bands and Homogeneity Test
Equal-Precision Bands
Displaying the Patients-at-Risk Table inside the Plot
Displaying the Patients-at-Risk Table outside the Plot
Modifying At-Risk Table Times
Reordering the Groups
Suppressing the Censored Observations
Failure Plots

If you need to modify the Kaplan-Meier plot, begin by looking at this chapter. You might find exactly (or at least almost exactly) what you need. You will find that it often takes only a few lines of code to modify a long and complicated template. The examples are based on many customer requests. If you find that you need to do something that is not covered, please let me know. I can add new examples to future editions.

Share

About Author

Warren F. Kuhfeld

Distinguished Research Statistician

Warren F. Kuhfeld is a distinguished research statistician developer in SAS/STAT R&D. He received his PhD in psychometrics from UNC Chapel Hill in 1985 and joined SAS in 1987. He has used SAS since 1979 and has developed SAS procedures since 1984. Warren wrote the SAS/STAT documentation chapters "Using the Output Delivery System," "Statistical Graphics Using ODS," "ODS Graphics Template Modification," and "Customizing the Kaplan-Meier Survival Plot." He also wrote the free web books Basic ODS Graphics Examples and Advanced ODS Graphics Examples.

Leave A Reply

Back to Top