Programming the statistical procedures from SAS

phreg format legend values

Reply
Occasional Contributor
Posts: 13

phreg format legend values

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;

 

Super User
Posts: 23,727

Re: phreg format legend values

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;

 


 

Occasional Contributor
Posts: 13

Re: phreg format legend values

Hi Reeza,

 

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

Super User
Posts: 23,727

Re: phreg format legend values

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;
Ask a Question
Discussion stats
  • 3 replies
  • 122 views
  • 0 likes
  • 2 in conversation