BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ra-v
Calcite | Level 5

Hello, I have a problem with my legend - I cannot fit it into my graph, it always get clipped no matter what height/width/legendarea I use (it is important for me to keep this height and width as in the code). I'm using SAS 9.4 This is my code:

ods graphics / width=600 height=300 maxlegendarea=45 attrpriority=none;
proc sgplot DATA=vintagr noborder;
	series x=seniority y=vintage3 /group=fin_period lineattrs=(pattern=solid) markers;
	xaxis display=(nolabel) integer values=(2 to 36);
	yaxis display=(nolabel noline) grid gridattrs=(thickness=2) integer values=(0 to 0.09 by 0.01);
	keylegend / title='' across=9 noborder down=4;
run;

and my data is attached to file. If I try to use discretelegend statement with displayclipped=TRUE, to at least partially see the legend, I always get an error, as my SAS does not recognize displayclipped as an option of discretelegend.

 

Best regards

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

The data shows you have 36 distinct groups.  There are three ways to address this. 

1.  Increase MaxLegendArea.  You already increased this to  45.  You can go higher.

2.  You can reduce the displayed LINELENGTH in the legend.  LineLength=24 may work.  For solid lines, lower value will work.

3.  Another way is to separate your year and month into new columns.  Now, you can color your lines by month (12) and use linepattern to show the year (3)  using GROUPLC and GROUPLP options (see some examples in Graphically Speaking - Spaghetti Plot). Now, you need two legends, one for the color, which can be a short line (linelength=10), or just TYPE=COLOR, and one for patterns (3).  Note, you still need the fin_priority group column.

 

series x=seniority y=vintage3 / group=fin_period grouplc=month grouplp=year lineattrs=(thickness=2);

 

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

It appears that you are attempting to show about 36 separate series (3 years of monthly values I would guess for you group variabl) on a single graph.

If you do not display any legend is the graph useful? That is so many lines I have a hard believing that graph is very readable.

 

VALUEATTRS in the Keylegend statement would allow you to specify size and font of the text used which may help considerably depending on which actual ODS destination and associated default font's are used. AUTOITEMSIZE would help adjust markers to match set font sizes. LINELENGTH in the Keylegend could also be used to shorten legend line segments to provide more room.

 

 

 

Note that a TEXT file is not data as we do not know what labels, formats or data types you assigned to variables. All of which can have some bearing on the appearance.

Ra-v
Calcite | Level 5

thank you, everything worked 🙂 

Jay54
Meteorite | Level 14

The data shows you have 36 distinct groups.  There are three ways to address this. 

1.  Increase MaxLegendArea.  You already increased this to  45.  You can go higher.

2.  You can reduce the displayed LINELENGTH in the legend.  LineLength=24 may work.  For solid lines, lower value will work.

3.  Another way is to separate your year and month into new columns.  Now, you can color your lines by month (12) and use linepattern to show the year (3)  using GROUPLC and GROUPLP options (see some examples in Graphically Speaking - Spaghetti Plot). Now, you need two legends, one for the color, which can be a short line (linelength=10), or just TYPE=COLOR, and one for patterns (3).  Note, you still need the fin_priority group column.

 

series x=seniority y=vintage3 / group=fin_period grouplc=month grouplp=year lineattrs=(thickness=2);

 

 

 

Ra-v
Calcite | Level 5
amazing, thanks!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 5 replies
  • 9199 views
  • 1 like
  • 3 in conversation