BookmarkSubscribeRSS Feed
MelissaM
Obsidian | Level 7

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?

3 REPLIES 3
ballardw
Super User

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.

MelissaM
Obsidian | Level 7
@ballardw First, Thank you for the response. Admittedly I shy away from annotate and any attrmaps. But I did try them both, along with SGPANEL, and am not grasping how they'd work. Need further guidance. So I did "the right thing" and attached code example, as well as what I'm looking to achieve (in a picture). Would much appreciate any response that does not require me to go back and update things manually with revised data, later.
Again, thank you.
MelissaM
Obsidian | Level 7
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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 490 views
  • 0 likes
  • 2 in conversation