Hi:
With the SG procedures, you can specify an INSET statement, which is where I would tend to put the count information, instead of into the legend. It may be a moot point, because I believe that the ODS ESCAPECHAR functions like {unicode} will work in the legend, but not functions like the new line function.
Documentation for the KEYLEGEND statement is here:
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/discrete-stmt.htm
Documentation for the INSET statement is here:
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/inset-stmt.htm
An example of naming a plot and then generating a legend for that plot is shown here:
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/a003155743.htm
Note the legendlabel= option and the name= option and how they work together with the keylegend specification.
When I order date variables, even if I have a character variable, as you do for grouping, I generally sort by the date order before the graph step and then use ORDER=DATA or some option like that. For SGPLOT, the option is DISCRETEORDER=DATA. Rather than use a format, I generally make a character variable, that way, I don't have to remember to keep the format around everywhere.
cynthia
[pre]
proc format;
value mfmt
"01Jan08"d, "01Feb08"d, "01Mar08"d = "Jan-Mar 08"
"01Apr08"d, "01May08"d, "01Jun08"d = "Apr-Jun 08"
"01Jul08"d, "01Aug08"d, "01Sep08"d = "Jul-Sep 08"
"01Oct08"d, "01Nov08"d, "01Dec08"d = "Oct-Dec 08"
"01Jan09"d, "01Feb09"d, "01Mar09"d = "Jan-Mar 09"
"01Apr09"d, "01May09"d, "01Jun09"d = "Apr-Jun 09";
run;
data Clinic_Stats;
length month $5 Clinic $11;
infile datalines;
input monyy : monyy5. num_surg tot_pts Clinic $;
mgrp = put(monyy,mfmt.);
format monyy monyy5.;
label mgrp = 'Month'
monyy = 'Month'
num_surg = 'Number Surgeries'
tot_pts = 'Total Patients'
Contact_Resp = 'Respiratory Therapy Avg Time'
Clinic = 'Clinic';
return;
datalines;
JAN08 50 838 Main
FEB08 44 903 Main
MAR08 61 809 Main
APR08 53 489 Main
MAY08 53 249 Main
JUN08 40 285 Main
JUL08 41 242 Main
AUG08 57 292 Main
SEP08 49 298 Main
OCT08 63 497 Main
NOV08 64 920 Main
DEC08 62 907 Main
JAN09 67 854 Main
FEB09 68 896 Main
MAR09 75 865 Main
APR09 74 876 Main
;
RUN;
proc sort data=clinic_stats out=clinic_stats;
by monyy;
run;
ods listing;
proc sgplot data=clinic_stats;
vbar mgrp / datalabel stat=sum freq=num_surg;
title 'SGPLOT -- vbar ordered line and inset';
xaxis label = 'Month' fitpolicy=stagger type=discrete
discreteorder=data;
yaxis label = 'Total Surgeries' values=( 0 to 225 by 25);
inset (" Jan08 " = " 838" " Feb08 " = " 903" " Jan09 "=" 854") /
border
title='Patients' position=topright
textattrs=GraphLabelText;
run;
proc sgplot data=clinic_stats;
vbar mgrp / group=monyy datalabel stat=sum freq=num_surg;
title 'SGPLOT -- Grouped vbar ordered line and inset';
xaxis label = 'Month' fitpolicy=stagger type=discrete
discreteorder=data;
yaxis label = 'Total Surgeries' values=( 0 to 225 by 25);
inset (" Jan08 " = " 838" " Feb08 " = " 903" " Jan09 "=" 854") /
border
title='Patients' position=topright
textattrs=GraphLabelText;
run;
[/pre]