Programming the statistical procedures from SAS

Proc Lifetest - Change Legend Title

Accepted Solution Solved
Reply
Grand Advisor
Posts: 16,925
Accepted Solution

Proc Lifetest - Change Legend Title

Is there a way to change the legend title in PROC LIFETEST without going into proc template?

It seems weird that it doesn't pick up the variable label....

Ie using the SAS valung dataset from the documentation

ods graphics on;

proc lifetest data=VALung plots=(s,ls,lls) outtest=Test maxtime=600;

   time SurvTime*Censor(1);

   id Therapy;

   strata Cell;

   label Cell='My Legend Label';

run;

ods graphics off;


Accepted Solutions
Solution
‎05-04-2012 02:35 PM
SAS Employee
Posts: 29

Re: Proc Lifetest - Change Legend Title

This is not updated in the latest version of SAS (9.3). I was running a trial version of SAS 12.1, and it works fine there.

The easiest way to work-around this is to use SAS Graphics Editor as I explained in the previous post.

For more persistent change, I recommend to modify the STRATA variable label in the legend via template modifications. You can easily change the title with a minimal understanding of the graph template language (GTL) as described below:

     1. Submit ‘ODS TRACE ON;' before you submit your LIFETEST statements.

     This displays the template names in the SAS log.

     The template name for the survival plot is Stat.Lifetest.Graphics.ProductLimitSurvival.

     2. Submit:

      proc template;

         source Stat.Lifetest.Graphics.ProductLimitSurvival;

      run;

      This displays the template source code in the SAS log.

     3. Copy and paste the source code to your editor.

     proc template;

        paste the source code here

     run;

     4. Modify the source code to specify the custom title in the DiscreteLegend statement:

      DiscreteLegend "Survival"/ title=GROUPNAME location=outside;

      >>

     DiscreteLegend “Survival”/ title=”custom label goes here” location=outside;

     5. Run the updated PROC TEMPLATE, then run PROC LIFETEST.

This should update your legend title.

Funda

View solution in original post


All Replies
SAS Employee
Posts: 29

Re: Proc Lifetest - Change Legend Title

I am not sure why your legend title did not work. When I run your program, the legend title shows up fine in all three graphs.

You can make immediate changes to your plots by using the ODS Graphics Editor, a point-and-click interface with which you can customize titles, annotatepoints, and make other enhancements. You can enable the creation of editable graphs within a SAS session by submitting one of the following statements:

ods listing sge=on;

ods html sge=on;

For details about the tools available in the ODS Graphics Editor, see the SAS ODS Graphics Editor: User’s Guide: http://support.sas.com/documentation/cdl/en/grstateditug/63427/HTML/default/viewer.htm#p0fa3opdl6xnz...

Funda

Grand Advisor
Posts: 16,925

Re: Proc Lifetest - Change Legend Title

It gets labeled as Cell not the label specified, ie "My Legend Label"

This happens in SAS 9.2 TS2M3 AND SAS 9.3TS1M0

Was it updated in a later release?

SurvivalPlot.png

70   ods graphics on;

71

72   proc lifetest data=VALung plots=(s,ls,lls) outtest=Test maxtime=600;

73

74      time SurvTime*Censor(1);

75

76      id Therapy;

77

78      strata Cell;

79

80      label Cell='My Legend Label';

81

82   run;

NOTE: The LOGLOG transform is used to compute the confidence limits for the quartiles of the survivor

      distribution. To suppress using this transform, specify CONFTYPE=LINEAR in the PROC LIFETEST statement.

NOTE: The data set WORK.TEST has 0 observations and 3 variables.

NOTE: PROCEDURE LIFETEST used (Total process time):

      real time           12.71 seconds

      cpu time            1.14 seconds

83

84   ods graphics off;

Solution
‎05-04-2012 02:35 PM
SAS Employee
Posts: 29

Re: Proc Lifetest - Change Legend Title

This is not updated in the latest version of SAS (9.3). I was running a trial version of SAS 12.1, and it works fine there.

The easiest way to work-around this is to use SAS Graphics Editor as I explained in the previous post.

For more persistent change, I recommend to modify the STRATA variable label in the legend via template modifications. You can easily change the title with a minimal understanding of the graph template language (GTL) as described below:

     1. Submit ‘ODS TRACE ON;' before you submit your LIFETEST statements.

     This displays the template names in the SAS log.

     The template name for the survival plot is Stat.Lifetest.Graphics.ProductLimitSurvival.

     2. Submit:

      proc template;

         source Stat.Lifetest.Graphics.ProductLimitSurvival;

      run;

      This displays the template source code in the SAS log.

     3. Copy and paste the source code to your editor.

     proc template;

        paste the source code here

     run;

     4. Modify the source code to specify the custom title in the DiscreteLegend statement:

      DiscreteLegend "Survival"/ title=GROUPNAME location=outside;

      >>

     DiscreteLegend “Survival”/ title=”custom label goes here” location=outside;

     5. Run the updated PROC TEMPLATE, then run PROC LIFETEST.

This should update your legend title.

Funda

Grand Advisor
Posts: 16,925

Re: Proc Lifetest - Change Legend Title

Thanks. I do know how to change the template, was hoping there was an easier way. Its good to know it will be updated in a later version.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 2404 views
  • 0 likes
  • 2 in conversation