BookmarkSubscribeRSS Feed
Pepperoni
Calcite | Level 5

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

6 REPLIES 6
Jay54
Meteorite | Level 14

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

    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:

Reeza
Super User

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:

http://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_templt_a0000...

Also, you didn't say it, but make sure you create your curve using the ODS graphics feature, it looks much better.

Pepperoni
Calcite | Level 5

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;

Jay54
Meteorite | Level 14

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;

Pepperoni
Calcite | Level 5

Thank you so much!

Pep

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1098 views
  • 0 likes
  • 4 in conversation