Hi everyone,
I'm doing a Kaplan-Meier survival graph (proc lifetest) with two curves on it (comparing two cancer treatments). The two treatments are listed in the datalines as medication=0 and medication=1. So the graph legend shows the red line as medication=0 and the blue line as medication=1.
OK! Now, I'd like the legend to look a little nicer. Is there a line of code I can add that would basically tell SAS: "In the legend of the graph, replace the term medication=0 with the text 'Green Eggs', and replace the term medication=1 with the text 'Ham' "?
Bogus example, of course - just in case my professor is trolling these forums. But I'm asking how to change the text of the legend.
Any help will be greatly appreciated by this newbie!
Thanks,
Pep
Reading the following MAY help: http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#legendchap.htm
I assume you are using a grouped step plot. You can define a User Defined Format and apply it to the group variable.
proc format;
value v
0='Green Eggs'
1='Ham';
run;
proc sgplot data=greeneggsandham;
format trt v.;
step x=time y=value / group=trt;
run;
See my blog post on Survival Plots:
Apply the format as Sanjay has suggested.
But if you want to change other things on the graph, such as title and axis labels check out this page:
Also, you didn't say it, but make sure you create your curve using the ODS graphics feature, it looks much better.
You guys are great! Thank you!
I'm obviously still doing something wrong, though... So I'm pasting my code below - can you tell me what I'm doing wrong?
Thanks!
Pep
'assayresult = 1 = IH positive
'assayresult = 0 = IH negative
'survstatus = 1 = died
'survstatus = 0 = censored
'So use the code below for SAS:
DATA Sedmak;
INPUT assayresult time survstatus;
DATALINES;
0 19 1
0 25 1
0 30 1
0 34 1
0 37 1
0 46 1
0 47 1
0 51 1
0 56 1
0 57 1
0 61 1
0 66 1
0 67 1
0 74 1
0 78 1
0 86 1
0 122 0
0 123 0
0 130 0
0 130 0
0 133 0
0 134 0
0 136 0
0 141 0
0 143 0
0 148 0
0 151 0
0 152 0
0 153 0
0 154 0
0 156 0
0 162 0
0 164 0
0 165 0
0 182 0
0 189 0
1 22 1
1 23 1
1 38 1
1 42 1
1 73 1
1 77 1
1 89 1
1 115 1
1 144 0
;
ods rtf;
proc format;
value assayresult
0='IH-Negative'
1='IH-Positive';
run;
proc sgplot data=Sedmak;
format assayresult;
step x=time y=survstatus / group=assayresult;
run;
PROC LIFETEST DATA=Sedmak METHOD=KM PLOT=(S);
TIME time*survstatus(0);
STRATA assayresult;
TEST;
RUN;
ods rtf close;
While it is not clear what you are looking for, If you just want to change the values shown in the legend, you only need to apply the format to the class variable before (or in) the LIFETEST procedure. You don't need proc SGPLOT at all. The Survival plot drawn by the LIFETEST proc will show the formatted values in the legend.
proc format;
value assayresult
0='IH-Negative'
1='IH-Positive';
run;
ods graphics on;
PROC LIFETEST DATA=Sedmak METHOD=KM PLOT=(S);
format assayresult assayresult.;
TIME time*survstatus(0);
STRATA assayresult;
TEST;
RUN;
Thank you so much!
Pep
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.