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

Hi all,

 

I am wondering if there's any way to make the legend title and labels left justified in PROC SGPLOT, because I have a long legend title. Here is the example of my current situation:

 

sasforum4.png

 

I generated this legend using KEYLEGEND statement and put it on the upper left corner. As is shown above, I want to move "<= 5 mg/kg/day" and "> 5 mg/kg/day" to the left, which is to left justify with the legend title "xxxxxxx". Is there any way to do that? 

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

You may need to place the legend with a blank title, and add the title using SGAnnotate.

See Dan's paper:  https://support.sas.com/resources/papers/proceedings11/277-2011.pdf

View solution in original post

8 REPLIES 8
Reeza
Super User

Are you using KEYLEGEND? EDIT: You said you were 🙂

 

A manual kludged method assuming no one else has a better solution, what happens if you add some trailing spaces at the end of the labels, either spaces or tabs (09)? Does that force it to the left more?

 

"> 5 mg/kg/day                       "

 


@Chaupak wrote:

Hi all,

 

I am wondering if there's any way to make the legend title and labels left justified in PROC SGPLOT, because I have a long legend title. Here is the example of my current situation:

 

sasforum4.png

 

I generated this legend using KEYLEGEND statement and put it on the upper left corner. As is shown above, I want to move "<= 5 mg/kg/day" and "> 5 mg/kg/day" to the left, which is to left justify with the legend title "xxxxxxx". Is there any way to do that? 


 

Chaupak
Obsidian | Level 7
Hi Reeza, thanks for your suggestion, but it seems like the space was trimmed when I tried.
Reeza
Super User
Spaces will likely be, you'll need to add tabs or a different form of white space. If you have example code to play with that would help.
Jay54
Meteorite | Level 14

You may need to place the legend with a blank title, and add the title using SGAnnotate.

See Dan's paper:  https://support.sas.com/resources/papers/proceedings11/277-2011.pdf

Chaupak
Obsidian | Level 7
I tried this way and it helps! I added the legend title using sganno manually, and adjusted the legend position using OUTERPAD= in KEYLEGEND. Thank you!
Chaupak
Obsidian | Level 7

I tried using '09'x, but it still didn't work. This link says that the tab character will be converted as blanks when the codes are submitted, when using the enhance editor (if I didn't misunderstand). I think add a legend title manually using annotation may help, like what Jay recommended. Thank you!

Ksharp
Super User

As Reeza said ,try TAB character '09'x , NOT blank character.

GraphGuy
Meteorite | Level 14

Another option is to use SAS/Graph Proc Gplot (rather than Base Proc SGplot).

 

Here's a short example:

 

legend1 position=(top left inside) across=1 
   label=(position=top 'xxxxxxxxxxxxxxxxxxxxxx');
symbol value=none interpol=join;
proc gplot data=sashelp.stocks;
plot close*date=stock / legend=legend1;
run;

GraphGuy_0-1645838338499.png

 

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
  • 8 replies
  • 3176 views
  • 6 likes
  • 5 in conversation