University of Rochester Medical Center
SearchDirectoryNewsEventsStrong HealthURMC Home

SAS Helpful Hints

Proc Lifetest with Gplot Survival Plot

Survival analysis is very simple to run using the Lifetest procedure. You need time to endpoint or completion, and a yes/no variable to indicate endpoint or completion. A group or stratification variable is often used for treatment groups.

I have added a Gplot to create a nice survival plot from the data generated by the Lifetest procedure. I have included many of my favorite graphic options to improve the appearance of the graph, and provide you with options you may wish to modify.

* Just a little data for an example;
Data work.A;
    Input treatment days endpoint @@;
    Cards;
1 1 0 1 2 0 1 3 1 1 4 0 1 5 0 1 6 0 1 7 1 1 8 0 1 9 1 1 10 1
2 1 0 2 2 0 2 3 0 2 4 0 2 5 1 2 6 0 2 7 0 2 8 0 2 9 0 2 10 1
3 1 1 3 2 1 3 3 0 3 4 1 3 5 0 3 6 1 3 7 0 3 8 1 3 9 1 3 10 0
;
Run;

Title1 Font=Centx Height=2 'Survival Analysis: Time to Reaching an Endpoint';

Proc Format;
    Value treat 1='Blue' 2='Red' 3='Green';
Run;

Proc Lifetest Data=work.A Outsurv=work.B Method=Km Plots=(s);
    Time days*endpoint(0); *(censored value);
    Strata treatment;
Run;

Data work.C;
    Set work.B;
    endpoints=100.0-100.0*survival;
    Label endpoints='%Reaching Endpoint' survival='%Surviving';
Run;

Goptions Device=Win Colors=(Black White Blue Red Green Gold Magenta)
Display Fby=Centx Hby=2 Cback=White;

Axis1 Width=2 Major=(Width=2) Minor=(Width=2) Value=(Font=Duplex Height=2) Order=0 To 100 By 10
        Label=(Angle=90 Rotate=0 Font=Centx Height=2 'Percent Reaching Endpoint');

Axis2 Width=2 Major=(Width=2) Minor=(Width=2) Value=(Font=Duplex Height=2)
        Label=(Font=Centx Height=2 'Time');

Legend1 Label=(Font=Centx Height=2) Value=(Font=Centx Height=2)
    Across=3 Down=1 Position=(Outside|Inside Top|Middle|Bottom Left|Center|Right);
Symbol1 Value=None Interpol=Steplj Line=1 Width=2 Bwidth=2 Color=Blue;
Symbol2 Value=None Interpol=Steplj Line=1 Width=2 Bwidth=2 Color=Red;
Symbol3 Value=None Interpol=Steplj Line=1 Width=2 Bwidth=2 Color=Green;
Symbol4 Value=None Interpol=Steplj Line=1 Width=2 Bwidth=2 Color=Gold;
Symbol5 Value=None Interpol=Steplj Line=1 Width=2 Bwidth=2 Color=Magenta;

Proc Gplot Data=work.C;
    Plot endpoints*days=treatment / Vaxis=Axis1 Haxis=Axis2 Legend=Legend1;
    Label days='Days' treatment='Treatment';
    Format treatment treat.;
Run;


Please send your comments and suggestions about this web page to A. Watts (watts@bst.rochester.edu)