BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
joesmama
Obsidian | Level 7

Hello, 

 

Using SGPLOT for the first time and need help figuring out how to adjust/compress  the Y-axis so that the legend can appear on the graph. As of now, the legend is absent from the graphs. I;ve looked through the documentation but haven't found anything that specifically addresses this. Any and all ideas are appreciated. 

 

proc sgplot data=survplot4;
step x=time y=survival / group=stratum name='s';
xaxis min=0 max=360 values=(0 to 360 by 60); title 'Survival in Months';
yaxis min=0 max=1 values=(0 to 1 by 0.1);
keylegend 's' / linelength=20;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
JeffMeyers
Barite | Level 11
Did you try setting ODS GRAPHICS / reset MAXLEGENDAREA=100; ? If that doesn't fix it then I would try running your original data through the LIFETEST procedure and grab the graph from there, and then post the picture here so we can see exactly how long your labels are and if there's some funny characters in there you're not seeing.

View solution in original post

6 REPLIES 6
DanH_sas
SAS Super FREQ

On the ODS GRAPHICS statement, specify a larger LEGENDAREAMAX value. The default is 20% of your graph space. After that, the legend is dropped. Here is the doc for the option: https://go.documentation.sas.com/?docsetId=grstatproc&docsetTarget=p0kroq43yu0lspn16hk1u4c65lti.htm&...

joesmama
Obsidian | Level 7
Thank you for the reference.
ballardw
Super User

How long is the text displayed in the legend for your group variable STRATUM? I normally would not expect 20 groups to exceed the default area for a legend but if your text values are long I would also suggest considering if the current text could be reduced.

joesmama
Obsidian | Level 7

Thank you for your response.

 

I have 8 groups in my strata. I have shortened the names but still am not able to get the legend to appear. As well, I've tried adjusting the items suggested in the log to no avail. 

 

NOTE: Some graph legends have been dropped due to size constraints. Try adjusting the MAXLEGENDAREA=,
WIDTH= and HEIGHT= options in the ODS GRAPHICS statement.

 

As well, I've tried adjusting the items suggested in the log to no avail. The legend remains absent.  My other graphs using the same data run nicely, ust not this particular graph. I'm not sure how to proceed. Do you have further recommendations? Thank you. 

 

 

JeffMeyers
Barite | Level 11
Did you try setting ODS GRAPHICS / reset MAXLEGENDAREA=100; ? If that doesn't fix it then I would try running your original data through the LIFETEST procedure and grab the graph from there, and then post the picture here so we can see exactly how long your labels are and if there's some funny characters in there you're not seeing.
joesmama
Obsidian | Level 7

That did the trick!. I wasn't using "reset" before MAXLEGENDAREA. 

 

Many thanks. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4511 views
  • 1 like
  • 4 in conversation