Data visualization with SAS programming

How to Change Legend Label in PROC LIFETEST Procedure

Accepted Solution Solved
Reply
Super Contributor
Posts: 395
Accepted Solution

How to Change Legend Label in PROC LIFETEST Procedure

[ Edited ]

Hello everyone,

 

I’m on a project now which is related to pharmaceutical industry. I’m trying to change the legend label of the PROC LIFETEST procedure’s graph result. As you can see the following image, the legend labels seem as Kras=-1 Kras=0 Kras=1 however I need to see the reports as  Unknown(Kras=-1), Negative(Kras=0)  and Positive(Kras=1). I prepared a sample data set that does not express anything and I’m sharing with you that sample data set as below. How can I see the legend label’s as Unknown , Negative and Positive. Does anybody can lead me, please ?

 

DATA Have;
Length AVAL 8 KRAS 8;
Infile Datalines Missover;
Input AVAL KRAS ;
Datalines;
80 1
34 1
391 1
221 0
362 0
219 0
113 0
48 1
105 1
18 1
54 1
333 1
172 -1
235 0
81 0
;
Run;

PROC LIFETEST DATA=Have
	ALPHA=0.05
	METHOD=LIFE
	INTERVALS= 30 60 90 120 150 180	PLOTS(ONLY)=SURVIVAL ( STRATA=UNPACK );;
	STRATA KRAS;
	TIME AVAL;
RUN;

 

 

 

Thank you.


Desired.png

Accepted Solutions
Solution
‎01-24-2016 06:38 PM
Super User
Posts: 19,093

Re: How to Change Legend Label in PROC LIFETEST Procedure

Here's a post with an example of it being used Smiley Wink

The original question includes the proc format and it's used in the graphing procedure, though it's applied through proc datasets first. That isn't necessary, it can be applied directly in the statistical procedure.

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/How-To-Show-Variables-Legendlabel-and-Medi...

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,139

Re: How to Change Legend Label in PROC LIFETEST Procedure

Please tell us the release of SAS you are using and if you are willing to write your own program to create the graph.  If yes, do you prefer SGPLOT or GTL?

Super User
Posts: 19,093

Re: How to Change Legend Label in PROC LIFETEST Procedure

Have you tried creating a format and applying a format to the variable in the proc lifetest procedure?

Super Contributor
Posts: 395

Re: How to Change Legend Label in PROC LIFETEST Procedure

As far as I understand there are not any options to change the legend label in PROC LIFETEST. @Sanjay_SAS, I'm out office at the moment but I remember the release of SAS as 9.3 . Actually, I'm willing to change the legend label and If is it possible by the help of the GTL or GPLOT, I can write it. @Reeza No, I haven't tried creating a format and applying a format to the variable in the PROC LIFETEST procedure. Could you lead me to reach my aim, please ?

 

Thank you.

Super User
Posts: 19,093

Re: How to Change Legend Label in PROC LIFETEST Procedure

Your code doesn't seem to match your graph. Is that your actual proc lifetest?

 

Applying a format does change your legend

 

1. Create a format that maps your numbers to the text you want. Assume you call it kras_fmt.

See this paper.

 

2. Change your proc lifetest by adding the following line to your code, again assuming you've called it kras_fmt.

format kras kras_fmt.;

 

 

Super Contributor
Posts: 395

Re: How to Change Legend Label in PROC LIFETEST Procedure

Hello @Reeza ,

 

No, it isn't my actual PROC LIFETEST. I wrote this code to make easier to share with you. I didn't see any paper. Am I missing something ?

 

Thanks.

Super User
Posts: 19,093

Re: How to Change Legend Label in PROC LIFETEST Procedure

Solution
‎01-24-2016 06:38 PM
Super User
Posts: 19,093

Re: How to Change Legend Label in PROC LIFETEST Procedure

Here's a post with an example of it being used Smiley Wink

The original question includes the proc format and it's used in the graphing procedure, though it's applied through proc datasets first. That isn't necessary, it can be applied directly in the statistical procedure.

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/How-To-Show-Variables-Legendlabel-and-Medi...

Super Contributor
Posts: 395

Re: How to Change Legend Label in PROC LIFETEST Procedure

Thank you @Reeza, The following code is working . After you adviced me the Proc Format I was trying to find my Box-Whisker . How can you find it ? But I want to ask one more question, apart from Proc Format is there any method to create my desired output ? Let me check on customer place . If it works there then I'll close this discussion. 

 

Thanks.

 

 


proc format;
value Kras_fmt
-1='Negative'
0='Unknown'
1='Positive'
;
run;
PROC LIFETEST DATA=Have
     ALPHA=0.05
     METHOD=LIFE
     INTERVALS= 30 60 90 120 150 180 PLOTS(ONLY)=SURVIVAL ( STRATA=UNPACK );
    Format Kras Kras_fmt.;
     STRATA KRAS;
     TIME AVAL;
RUN;

 

Super User
Posts: 19,093

Re: How to Change Legend Label in PROC LIFETEST Procedure

Other options:

1. Recode variable into a character variable directly

2. Extract Data from proc lifetest and use a graphic procedure

3. Look at macro suggestions from SAS in documentation to modify survival curves.

 

How did I find your post? Search term: PROC FORMAT Limit by User on left hand menu to Turcay.

Super Contributor
Posts: 395

Re: How to Change Legend Label in PROC LIFETEST Procedure

@Reeza, Thank you for the information, I will try the other options as soon as possible.

 

 

☑ This topic is solved.

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

Discussion stats
  • 10 replies
  • 810 views
  • 0 likes
  • 3 in conversation