I have a keylegend in an SGPLOT and I need to left justify the title that appears in the legend. Is there a way to do that? I can't find anything in the documentation.
Thanks!
When you say the title that appears in the keylegend, do you mean the variable name?
It is always a good idea to include your code and perhaps some example data.
Sorry, I got lazy and hoped there would be a simple, "Oh yeah!" solution. Here's the code below and the graph is attached. I want to spread the KEYLEGEND title out where the "Customer Loyalty" piece of the legend title is spread out across the first 4 variables listed in the legend and have the "Dealer Performance" piece of the legend title spread out over the remaining 5 variables listed in the legend.
In other words:
"Customer Loyalty" spreads across OSAT, Dealer Preference, Likely to Recommend, and More Likely to Purchase
"Dealer Performance" spreads across WADO, TTIA, COMM, TTSE, and RSAT
ods graphics on / height=800 width=1600 maxlegendarea=40;
title;
footnote;
TITLE1 h=5.0 BOLD f="Thorndale AMT" "&SEL_MGMT_GRP. - Customer Loyalty Along With Dealer Performance";
title2 h=2.0 bold c=brown "&SEL_MGMT_GRP. vs. National and Region";
proc sgplot data=ALL_AVERAGES_XPOSED;
vbarparm category=level response=value / group=entity groupdisplay=cluster dataskin=pressed
seglabel seglabelattrs=(weight=bold color=white size=7) name="VBAR1";
xaxis display=(nolabel);
yaxis values=(0 to 1 by .1);
keylegend "VBAR1" /
title="Customer Loyalty Dealer Performance";
where level in("National" "Regional" "Management_Group");
run;
Thanks.
There are two ways I would see going about this.
The first is a really mind numbingly inefficient way and that is to add spaces in your title between the two statements until they are spaced out enough that you are satisfied.
The second way would be efficient but requires knowledge of the Graph Template Language. I don't have the data to test to make sure this runs OK, but here is what I'd do. It essentially splits your legend into two and allows you to have two separate titles in the two pieces by using the EXCLUDE option. This option also exists in KEYLEGEND but I don't know if there's a way to place to legends side-by-side with just SGPLOT as I'm afraid they would overlay on top of each other.
Here's a reference to the GTL syntax: http://support.sas.com/documentation/cdl//en/grstatgraph/69718/HTML/default/viewer.htm#n07s2oezv7f65...
ods path WORK.TEMPLAT(UPDATE) SASHELP.TMPLMST (READ);
proc template;
define statgraph barcharts;
begingraph / designwidth=1600 designheight=800;
layout lattice / rows=1 columns=1; /**This is added to give us access to the SIDEBAR block**/
sidebar / align=bottom; /**Sidebar is the space at the bottom of the image (below the actual graph)**/
layout gridded / rows=1 columns=2 border=true; /**This allows us to create two spaces within the sidebar**/
/**Makes a legend on the same graph, but excludes the values you don't want under that specific title**/
discretelegend "VBAR1" / title="Customer Loyalty" across=4 border=false exclude=('WADO' 'TTIA' 'COMM' 'TTSE' 'RSAT');
discretelegend "VBAR1" / title="Dealer Performance" across=4 border=false exclude=('OSAT' 'Dealer Preference' 'Likely to Recommend' 'More Likely to Purchase');
endlayout;
endsidebar;
layout overlay /
/*Sets up the axes*/
xaxisopts=(display=(line ticks tickvalues))
yaxisopts=(type=linear linearopts=(viewmin=0 viewmax=1 tickvaluesequence=(start=0 end=1 increment=0.1)));
/**Barchart syntax is slightly different in GTL**/
barchartparm category=level response=value / group=entity orient=vertical groupdisplay=cluster dataskin=pressed
segmentlabeltype=auto segmentlabelattrs=(weight=bold color=white size=7) name="VBAR1";
endlayout;
endlayout;
endgraph;
end;
run;
ods graphics on / height=800 width=1600 maxlegendarea=40;
proc sgrender data=ALL_AVERAGES_XPOSED template=barcharts;
where level in("National" "Regional" "Management_Group");
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: