SAS 9.4M6 SGPlot
Am outputting the following to ODS PDF:
SGPLOT, a BY Group, and multiple SERIES statements.
Some of the legend is AUTOLEGEND generated. Some is LEGENDITEM generated.
The legend is necessarily large, and has taken over the page.
I would prefer to:
(1) remove the legend from each page, and
(2) print one legend at the front of the PDF.
Is there a way to do this?
Since you in effect one "plot" that is the legend and then the actual plots I would suggest creating an annotate data set and displaying that for the legend and then removing legends from the individual plots. Then just display the annotate set results.
If you data changes much this can be a bit of a chore and you might want to consider using DATTRMAP or RATTRMAP data sets to make things more consistent in the graphs.
Kind of generic answer to a generic question. Examples of your SGPLOT code might let someone provide a bit more detailed suggestion, and better would be to provide some example data that behaves like your data set to demonstrate the issue.
Sometimes an SGPLOT by group may be handled a bit nice with SGPANEL and a Panelby statement.
proc sort data=sashelp.class out=class;by sex;run;
proc sgplot data = class ;
by sex;
scatter x = height y = weight / name = 'A' LEGENDLABEL="Height";
scatter x = age y = weight / name = 'B' LEGENDLABEL="Weight";
legenditem name="C" type=marker / markerattrs=(symbol=TriangleLeftFilled size=8pt Color=red)
label="Misc Legend Item #1";
legenditem name="D" type=marker / markerattrs=(symbol=TriangleRightFilled size=8pt color=blue)
label="Misc Legend Item #2";
legenditem name="E" type=text / text="SUBJ"
label="Misc Legend Item #3";
keylegend 'A' 'B' 'C' 'D' 'E' / position = e;
title;footnote;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.