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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.