%let gpath='C:\';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;;
proc format;
value group
1="<50" 2="50-80" 3=">80";
run;
/*--Data with 3 bars--*/
data bar3;
format Grp group.;
input Loc $ Value;
if value < 50 then Grp=1;
else if value < 80 then Grp=2;
else Grp=3;
datalines;
A 60
B 40
C 90
;
run;
/*--Data with 3 bars--*/
data bar2;
format Grp group.;
input Loc $ Value;
if Value < 50 then Grp=1;
else if Value < 80 then Grp=2;
else Grp=3;
datalines;
C 85
B 55
;
run;
/*--Define Attr Map for group values using FORMATTED data--*/
data attrmap;
length value FillColor LineColor $8;
Id='X'; Value="<50"; FillColor='Red'; LineColor='Black'; output;
Id='X'; Value="50-80"; FillColor='Yellow'; LineColor='Black'; output;
Id='X'; Value=">80"; FillColor='Green'; LineColor='Black'; output;
run;
/*--Three bars--*/
ods graphics / reset width=5in height=3in imagename='BarAttrMapFmt_3_93';
title 'Value by Location';
proc sgplot data=bar3 dattrmap=attrmap;
vbar loc / response=value group=grp datalabel nostatlabel attrid=X;
refline 50 / lineattrs=(color=darkred) label='Action Limit' labelloc=inside labelpos=min;
refline 80 / lineattrs=(color=darkgreen) label='Goal' labelloc=inside labelpos=min;
xaxis display=(nolabel) discreteorder=data;
yaxis offsetmin=0;
run;
/*--Two bars--*/
ods graphics / reset width=5in height=3in imagename='BarAttrMapFmt_2_93';
title 'Value by Location';
proc sgplot data=bar2 dattrmap=attrmap;
vbar loc / response=value group=grp datalabel nostatlabel attrid=X;
refline 50 / lineattrs=(color=darkred) label='Action Limit' labelloc=inside labelpos=min;
refline 80 / lineattrs=(color=darkgreen) label='Goal' labelloc=inside labelpos=min;
xaxis display=(nolabel) discreteorder=data;
yaxis offsetmin=0;
run;
/*--Three bars with Attr Map--*/
ods graphics / reset width=5in height=3in imagename='BarFmt_3_93';
title 'Value by Location';
proc sgplot data=bar3;
vbar loc / response=value group=grp datalabel nostatlabel;
refline 50 / lineattrs=(color=darkred) label='Action Limit' labelloc=inside labelpos=min;
refline 80 / lineattrs=(color=darkgreen) label='Goal' labelloc=inside labelpos=min;
xaxis display=(nolabel) discreteorder=data;
yaxis offsetmin=0;
run;
/*--Two bars with Attr Map--*/
ods graphics / reset width=5in height=3in imagename='BarFmt_2_93';
title 'Value by Location';
proc sgplot data=bar2;
vbar loc / response=value group=grp datalabel nostatlabel;
refline 50 / lineattrs=(color=darkred) label='Action Limit' labelloc=inside labelpos=min;
refline 80 / lineattrs=(color=darkgreen) label='Goal' labelloc=inside labelpos=min;
xaxis display=(nolabel) discreteorder=data;
yaxis offsetmin=0;
run;
/*--Add all three group values at the top of the data in the right order--*/
data bar2A;
retain savevvalue;
drop savevvalue;
set bar2;
if _n_ = 1 then do;
savevvalue=value;
value=.; Grp=1; output; Grp=2; output; Grp=3; output;
value=savevvalue;
end;
output;
run;
/*ods html;*/
/*proc print;*/
/*var Loc Value Grp;*/
/*run;*/
/*ods html close;*/
/*--Two bars with Attr Map and all three legend entries--*/
ods graphics / reset width=5in height=3in imagename='BarAttrMapFmt_2All_93';
title 'Value by Location';
proc sgplot data=bar2a dattrmap=attrmap;
vbar loc / response=value group=grp datalabel nostatlabel attrid=X;
refline 50 / lineattrs=(color=darkred) label='Action Limit' labelloc=inside labelpos=min;
refline 80 / lineattrs=(color=darkgreen) label='Goal' labelloc=inside labelpos=min;
xaxis display=(nolabel) discreteorder=data;
yaxis offsetmin=0;
run;