I am using following code. i wanted legend as in the attached figure but i am getting two different leagends separately. How can i get desired legend? I am using SAS 9.3.
Desired legend.
proc means data=sashelp.class nway noprint;
class sex age;
var weight;
output out=_td_mean
mean=mean
lclm=low
uclm=high;
run;
proc template;
define statgraph highlow;
begingraph;
layout datapanel classvars=(sex)/columns=2
columngutter=5
headerlabeldisplay=value
headerlabelattrs=(weight=bold)
headerbackgroundcolor=lightgray
columnaxisopts=(display=(label tickvalues ticks line)
label=("Age (Years)") labelattrs=(weight=bold)
linearopts=(tickvaluepriority=true tickvaluelist=(1 2 3 6 9 12)))
rowaxisopts=(display=(label tickvalues ticks line)
label=("Mean Weight (kgs)") labelattrs=(weight=bold))
;
layout prototype;
seriesplot x=age y=mean/group=trt01p lineattrs=(pattern=solid) name='p';
scatterplot x=age y=mean/group=trt01p
yerrorlower=low
yerrorupper=high
markerattrs=(symbol=circlefilled) name='s';
referenceline y=50 / LINEATTRS = (PATTERN = DOT);
referenceline y=150 / LINEATTRS = (PATTERN = DOT);
endlayout;
sidebar / align=bottom;
discretelegend "s" "p" / border=false;
endsidebar;
endlayout;
endgraph;
end;
run;
ods graphics on/noborder;
proc sgrender data=_td_mean template=highlow;
run;
ods graphics off;
Use MERGEDLEGEND.
proc template;
define statgraph mergedLegend;
begingraph;
Layout overlay;
scatterplot x=age y=height / group=sex name='scatter';
seriesplot x=age y=height / group=sex name='series' connectorder=xaxis;
mergedlegend 'scatter' 'series';
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.class template=mergedLegend;
run;
Using 9.2 I get a single legend across the bottom. Adding Across=1 gets me a stacked legend at the bottom.
Thanks. I tried that as well. I am getting like above.
That sounds like the desired output. If you need different text then the LEGENDLABEL needs to be set for each of the plots.
The color and marker symbols would have to be set with the appropriate attributes for the plot.
Use MERGEDLEGEND.
proc template;
define statgraph mergedLegend;
begingraph;
Layout overlay;
scatterplot x=age y=height / group=sex name='scatter';
seriesplot x=age y=height / group=sex name='series' connectorder=xaxis;
mergedlegend 'scatter' 'series';
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.class template=mergedLegend;
run;
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.
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.