%let gpath='C:\';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--Add come variability to the data--*/
data electric;
set sashelp.electric;
keep year customer revenue;
revenue=revenue*(1+ranuni(2));
run;
/*proc print;run;*/
/*--Compute sum by Year and Customer--*/
proc means data=electric;
class year customer;
var revenue;
output out=elec(where=(_type_ ge 2))
sum(revenue) = Revenue;
run;
/*proc print;run;*/
/*--Sort by Year and Customer--*/
proc sort data=elec out=sorted;
by year customer;
run;
/*proc print;run;*/
/*--Compute each customer value as a % of the total for each year--*/
/*--Also compute Low, High and Mid values for each segment--*/
data pctByYear;
set sorted;
format Revenue dollar8. Pct Low High Mid percent6.0;
retain Total Low 0;
keep Customer Year Pct Low High Mid;
by year;
if first.year then do;
total=revenue;
low=0;
end;
else do;
Pct=revenue/total;
High=Low+pct;
Mid=(low+high)/2;
output;
low=high;
end;
run;
/*proc print;run;*/
proc sort data=pctByYear out=pctByYearDescending;
by year customer;
run;
/*proc print;run;*/
/*--HighLow VBAR with Scatter Overlay--*/
ods graphics / reset width=5in height=3in imagename='G100_HighLow_94';
title 'All groups in a category total 100%';
proc sgplot data=pctByYearDescending(where=(year < 2000));
highlow x=year low=low high=high / type=bar dataskin=gloss group=customer;
scatter x=year y=mid / markerchar=pct markercharattrs=(color=black size=7);
yaxis grid display=(nolabel) offsetmin=0;
xaxis display=(nolabel);
run;
/*--Cluster VBAR--*/
ods graphics / reset width=5in height=3in imagename='G100_Cluster_94';
proc sgplot data=pctByYearDescending(where=(year < 2000));
vbar year / response=pct group=customer groupdisplay=cluster dataskin=pressed
grouporder=data nostatlabel datalabel datalabelattrs=(size=7);
yaxis grid display=(nolabel);
xaxis display=(nolabel);
run;
title;