BookmarkSubscribeRSS Feed
NadiaK
Fluorite | Level 6

Hi everyone,

 

I've been working on survival analysis for a while now and it's been a long and painful process in SAS.

Any, I learned how to format the axis and titles of the plots generated. However, I would now like to format the legend values. I basically have four lines on my plot for the 4 treatments investigated. Instead of these treatments appearing as 1, 2 , 3 and 4, I would like to label them properly. Any ideas on how to do that? Below is the code that I've used so far. I think I should add some proc commands in there to do what I want to do, but don't know how or where.

 

proc template;
define statgraph Stat.PHReg.Graphics.Survival;
   dynamic title1 title2 title3 title4 xviewMin xviewMax group groupIndex groupName plotCL plotHPD
      transparency piecewise _byline_ _bytitle_ _byfootnote_;
   BeginGraph;
      entrytitle "Survival with BC by soft drink consumption" TITLE3;
      entrytitle TITLE2 TITLE4 / textattrs=GRAPHVALUETEXT;
      layout overlay / xaxisopts=(linearopts=(viewmin=XVIEWMIN viewmax=XVIEWMAX)) yaxisopts=(label=
         "All-cancer Survival Probability" shortlabel="All-cancer Survival" linearopts=(viewmin=0.5 viewmax=1 tickvaluelist=(
         0 .2 .4 .6 .8 1.0)));
         if (PLOTCL)
            bandplot LimitLower=LOWERSURVIVAL LimitUpper=UPPERSURVIVAL x=TIME / group=GROUP index=
               GROUPINDEX modelname="Survival" datatransparency=transparency;
         endif;
         if (PLOTHPD)
            bandplot LimitLower=LOWERHPDSURVIVAL LimitUpper=UPPERHPDSURVIVAL x=TIME / group=GROUP
               index=GROUPINDEX modelname="Survival" datatransparency=transparency;
         endif;
         if (EXISTS(PIECEWISE))
            seriesplot y=SURVIVAL x=TIME / group=GROUP index=GROUPINDEX name="Survival";
         else
            stepplot y=SURVIVAL x=TIME / group=GROUP index=GROUPINDEX name="Survival";
         endif;
         if (EXISTS(GROUP))
            discretelegend "Survival" / location=inside title="Freq. of soft drinks" 
autoalign=(Bottom BottomLeft Top TopRight); endif; endlayout; if (_BYTITLE_) entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT; else if (_BYFOOTNOTE_) entryfootnote halign=left _BYLINE_; endif; endif; EndGraph; end;

 

3 REPLIES 3
Reeza
Super User

Have you tried applying a format? That would be my usual recommendation, not sure it changes if using PROC SGRENDER.

 


@NadiaK wrote:

Hi everyone,

 

I've been working on survival analysis for a while now and it's been a long and painful process in SAS.

Any, I learned how to format the axis and titles of the plots generated. However, I would now like to format the legend values. I basically have four lines on my plot for the 4 treatments investigated. Instead of these treatments appearing as 1, 2 , 3 and 4, I would like to label them properly. Any ideas on how to do that? Below is the code that I've used so far. I think I should add some proc commands in there to do what I want to do, but don't know how or where.

 

proc template;
define statgraph Stat.PHReg.Graphics.Survival;
   dynamic title1 title2 title3 title4 xviewMin xviewMax group groupIndex groupName plotCL plotHPD
      transparency piecewise _byline_ _bytitle_ _byfootnote_;
   BeginGraph;
      entrytitle "Survival with BC by soft drink consumption" TITLE3;
      entrytitle TITLE2 TITLE4 / textattrs=GRAPHVALUETEXT;
      layout overlay / xaxisopts=(linearopts=(viewmin=XVIEWMIN viewmax=XVIEWMAX)) yaxisopts=(label=
         "All-cancer Survival Probability" shortlabel="All-cancer Survival" linearopts=(viewmin=0.5 viewmax=1 tickvaluelist=(
         0 .2 .4 .6 .8 1.0)));
         if (PLOTCL)
            bandplot LimitLower=LOWERSURVIVAL LimitUpper=UPPERSURVIVAL x=TIME / group=GROUP index=
               GROUPINDEX modelname="Survival" datatransparency=transparency;
         endif;
         if (PLOTHPD)
            bandplot LimitLower=LOWERHPDSURVIVAL LimitUpper=UPPERHPDSURVIVAL x=TIME / group=GROUP
               index=GROUPINDEX modelname="Survival" datatransparency=transparency;
         endif;
         if (EXISTS(PIECEWISE))
            seriesplot y=SURVIVAL x=TIME / group=GROUP index=GROUPINDEX name="Survival";
         else
            stepplot y=SURVIVAL x=TIME / group=GROUP index=GROUPINDEX name="Survival";
         endif;
         if (EXISTS(GROUP))
            discretelegend "Survival" / location=inside title="Freq. of soft drinks" 
autoalign=(Bottom BottomLeft Top TopRight); endif; endlayout; if (_BYTITLE_) entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT; else if (_BYFOOTNOTE_) entryfootnote halign=left _BYLINE_; endif; endif; EndGraph; end;

 


 

NadiaK
Fluorite | Level 6

Hi Reeza,

 

I'm not very familiar with SAS language. What do you mean by applying a format? Can you give me an example?

Reeza
Super User

This is an example of how you create a format:

proc format;
value dx_fmt
1 = 'Cancer'
2 = 'Heart'
3 = 'Diabetes'
4 = 'Multiple Conditions';
run;

 

Then you apply the format using a FORMAT statement.

 

format variableName dx_fmt.;

 

A full example here:

 

proc format;
value dx_fmt
1 = 'Cancer'
2 = 'Heart'
3 = 'Diabetes'
4 = 'Multiple Conditions'
other = 'Everything Else';
run;

data demo;
input dx;
cards;
1
2
3
4
5
6 
7
8
9

;
run;

title 'Printed without a format';
proc print data=demo;
run;

title 'Printed with a format';
proc print data=demo;
format dx dx_fmt.;
run;

*example of how its handled in a summary proc;
proc freq data=demo;
table dx;
format dx dx_fmt.;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1431 views
  • 0 likes
  • 2 in conversation