Programming the statistical procedures from SAS

Display BY group names in survival plots in PROC LIFETEST

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Display BY group names in survival plots in PROC LIFETEST

Dear Community,

My data set has an indicator variable named "BY_GROUPS" that shows the names of 2 groups: A and B.  I need to plot 2 different survival functions in PROC LIFETEST based on these 2 groups.  (Note that I am NOT trying to plot the 2 groups as 2 strata on the same survival plot.)

I can do this by running PROC LIFETEST with the BY statement.  However, I can't figure out how to display the names "A" and "B" in the plot.  The documentation and online resources don't reveal an answer.

Could you please help?

My sample code is below.

Thanks,

Eric

_________________________________________________________________________________              

PROC LIFETEST

     data = my_survival_data

                    method = KM

                    notable

                    plots = survival

                                   (

                                        CB

                                        atrisk

                                   );

     time survival_time * censor_variable(1);

     strata strata_group;

     by BY_GROUP;

run;


Accepted Solutions
Solution
‎11-10-2014 03:08 PM
Contributor
Posts: 40

Re: Display BY group names in survival plots in PROC LIFETEST

Hi Reeza,

I have SAS 9.3.

I found a simple solution.  Instead of using the "BY" statement in PROC LIFETEST to get the plots for the 2 groups, I used 2 separate PROC LIFETEST procedures to get the 2 plots.  I was then able to specify the group in my "TITLE" statements.  I used the "WHERE =" option to select the group that I wanted after specifying the data.

It's not very elegant, but it works.

PROC LIFETEST

     data = my_survival_data

                    (

                         where = (

                                        group = 'A'

                                     )

                    )

                    method = KM

                    notable

                    plots = survival

                                   (

                                        CB

                                        atrisk

                                   );

     time survival_time * censor_variable(1);

     strata strata_group;

     title 'Survival Plot for Group A';

run;

PROC LIFETEST

     data = my_survival_data

                    (

                         where = (

                                        group = 'B'

                                     )

                    )

                    method = KM

                    notable

                    plots = survival

                                   (

                                        CB

                                        atrisk

                                   );

     time survival_time * censor_variable(1);

     strata strata_group;

     title 'Survival Plot for Group B';

run;

View solution in original post


All Replies
Super User
Posts: 18,571

Re: Display BY group names in survival plots in PROC LIFETEST

What version of SAS are you on?

I know you can definitely do it by modifying the templates, if you have SAS 9.4 you may have an odstitle option but I'm not sure.

Here's instructions on how to modify the title by modifying the template.

SAS/STAT(R) 9.2 User's Guide, Second Edition

Solution
‎11-10-2014 03:08 PM
Contributor
Posts: 40

Re: Display BY group names in survival plots in PROC LIFETEST

Hi Reeza,

I have SAS 9.3.

I found a simple solution.  Instead of using the "BY" statement in PROC LIFETEST to get the plots for the 2 groups, I used 2 separate PROC LIFETEST procedures to get the 2 plots.  I was then able to specify the group in my "TITLE" statements.  I used the "WHERE =" option to select the group that I wanted after specifying the data.

It's not very elegant, but it works.

PROC LIFETEST

     data = my_survival_data

                    (

                         where = (

                                        group = 'A'

                                     )

                    )

                    method = KM

                    notable

                    plots = survival

                                   (

                                        CB

                                        atrisk

                                   );

     time survival_time * censor_variable(1);

     strata strata_group;

     title 'Survival Plot for Group A';

run;

PROC LIFETEST

     data = my_survival_data

                    (

                         where = (

                                        group = 'B'

                                     )

                    )

                    method = KM

                    notable

                    plots = survival

                                   (

                                        CB

                                        atrisk

                                   );

     time survival_time * censor_variable(1);

     strata strata_group;

     title 'Survival Plot for Group B';

run;

Super User
Posts: 18,571

Re: Display BY group names in survival plots in PROC LIFETEST

I assumed you were trying to change the default title. If title statements work try using the #byval(group) instead.

PROC LIFETEST

     data = my_survival_data

                  

                    method = KM

                    notable

                    plots = survival

                                   (

                                        CB

                                        atrisk

                                   );

     by group

     time survival_time * censor_variable(1);

     strata strata_group;

     title 'Survival Plot for Group #byval(group)';

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 359 views
  • 3 likes
  • 2 in conversation