%let gpath=C:\;
ods html close;
%let w=4in;
%let h=6in;
%let dpi=200;
ods listing gpath="&gpath" image_dpi=&dpi;
/*--Get statistics by origin and make--*/
proc means data=sashelp.cars(where=(type ne 'Hybrid')) noprint;
class origin make;
var msrp;
output out=cars(where=(_type_ > 2))
min=Low
max=High
mean=Mean;
run;
/*--Restructure data--*/
data cars2;
set cars(drop=_type_ rename=(_freq_=Freq));
by origin;
output;
if last.origin then do;
call missing(make, freq, low, high, mean);
output;
end;
run;
proc sort data=cars2 out=cars3;
by origin make;
run;
/*--Put the Origin as the first value in Make--*/
/*--Add Ref value for alternate values in Origin list--*/
data cars4;
drop origin;
set cars3;
subgroup=2;
indent=1;
if make='' then do; make=origin; subgroup=1; indent=0; count=0; end;
else do; ref=ifc(count=0, '', make); count+1; count=mod(count, 2); end;
run;
/*--Attribute maps for Subgroup Test attributes--*/
data attrmap;
length id textcolor textweight $10;
id='text'; value='1'; textcolor='Black'; textweight='bold'; output;
id='text'; value='2'; textcolor='Black'; textweight='normal'; output;
id='textColor'; value='1'; textcolor='Red'; textweight='bold'; output;
id='textColor'; value='2'; textcolor='Black'; textweight='normal'; output;
run;
/*--Create graph--*/
ods graphics / reset width=&w noscale height=&h imagename='Segmented_Bar_Chart';
title h=10pt 'MSRP Mean and Range by Make';
proc sgplot data=cars4 noborder dattrmap=attrmap;
refline ref / discretethickness=1 transparency=0.8;
scatter y=make x=mean / xerrorlower=low xerrorupper=high
markerattrs=(symbol=circlefilled size=5) noerrorcaps;
yaxistable make / position=left location=inside textgroup=subgroup textgroupid=text
indentweight=indent labelhalign=left nolabel;
yaxis display=none reverse fitpolicy=none colorbands=odd colorbandsattrs=(transparency=1);
xaxis display=(nolabel noticks noline) grid valueattrs=(size=7);
run;
/*--Create graph--*/
ods graphics / reset width=&w noscale height=&h imagename='Segmented_Bar_Chart_Color';
title h=10pt 'MSRP Mean and Range by Make';
proc sgplot data=cars4 noborder dattrmap=attrmap;
refline ref / discretethickness=1 transparency=0.8;
scatter y=make x=mean / xerrorlower=low xerrorupper=high
markerattrs=(symbol=circlefilled size=5) noerrorcaps;
yaxistable make / position=left location=inside textgroup=subgroup textgroupid=textcolor
indentweight=indent labelhalign=left nolabel;
yaxis display=none reverse fitpolicy=none colorbands=odd colorbandsattrs=(transparency=1);
xaxis display=(nolabel noticks noline) grid valueattrs=(size=7);
run;