%let gpath='C:\';
%let dpi=150;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--Stacked Group--*/
ods graphics / reset width=4in height=2.5in imagename='StackedBar';
proc sgplot data=sashelp.prdsale;
title 'Actual Sales by Product and Quarter';
vbar product / response=actual group=quarter stat=sum;
xaxis display=(nolabel);
yaxis grid label='Sales';
run;
/*--Stacked Group with top Labels--*/
ods graphics / reset width=4in height=2.5in imagename='StackedBarLabel';
proc sgplot data=sashelp.prdsale;
format actual dollar6.0;
title 'Actual Sales by Product and Quarter';
vbar product / response=actual group=quarter stat=sum
datalabel datalabelattrs=(weight=bold);
xaxis display=(nolabel);
yaxis grid label='Sales';
run;
/*--Summarize Actual by product and quarter--*/
proc means data=sashelp.prdsale;
class product quarter;
var actual;
output out=prdsale(where=(_type_ > 2) keep= product quarter ActualSum _type_)
sum=ActualSum;
run;
/*proc print;run;*/
/*--Compute high low levels for each quarter by product--*/
data HighLow;
format low mid high actualsum dollar7.0;
format highlabel dollar8.0;
retain low 0;
set prdsale (drop=_type_);
by product;
if first.product then low=0;
high=low+ActualSum;
mid = (low+high)/2;
if last.product then highlabel=high;
output;
low=high;
run;
/*proc print;run;*/
/*--Stacked Group with segment Labels--*/
ods graphics / reset width=4in height=2.5in imagename='StackedBarSegLabel';
proc sgplot data=HighLow;
title 'Actual Sales by Product and Quarter';
highlow x=product low=low high=high / group=quarter
type=bar lineattrs=(pattern=solid);
scatter x=product y=mid / markerchar=actualsum;
xaxis display=(nolabel);
yaxis grid offsetmin=0 label='Sales';
run;
/*--Stacked Group with segment and top Labels--*/
ods graphics / reset width=4in height=2.5in imagename='StackedBarAllLabel';
proc sgplot data=HighLow;
title 'Actual Sales by Product and Quarter';
highlow x=product low=low high=high / group=quarter
type=bar lineattrs=(pattern=solid) highlabel=highlabel
labelattrs=(weight=bold);
scatter x=product y=mid / markerchar=actualsum;
xaxis display=(nolabel);
yaxis grid offsetmin=0 label='Sales';
run;