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.
Here's a post with an example of it being used 😉
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.
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?
Have you tried creating a format and applying a format to the variable in the proc lifetest procedure?
As far as I understand there are not any options to change the legend label in PROC LIFETEST. @Jay54, 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.
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.;
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.
Here's a post with an example of it being used 😉
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.
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;
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.