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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 6796 views
  • 1 like
  • 3 in conversation