%let gpath='C:\';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--MirrorHistograms-Horizontal--*/
proc template;
define statgraph MirrorHistogramHorz;
dynamic _binwidth;
begingraph;
entrytitle 'Mileage Distribution';
layout lattice / order=columnmajor columnweights=(0.49 0.51) rowdatarange=union;
cell;
cellheader;
entry 'City Mileage';
endcellheader;
layout overlay / xaxisopts=(reverse=true griddisplay=on
linearopts=(tickvaluepriority=true tickvaluesequence=(start=0 end=25 increment=5)))
yaxisopts=(display=none reverse=true griddisplay=on
linearopts=(tickvaluesequence=(start=0 end=70 increment=10)));
histogram mpg_city / binstart=0 binwidth=_binwidth orient=horizontal binaxis=false
fillattrs=graphdata1 datatransparency=0.3;
endlayout;
endcell;
cell;
cellheader;
entry 'Highway Mileage';
endcellheader;
layout overlay / xaxisopts=(griddisplay=on
linearopts=(tickvaluepriority=true tickvaluesequence=(start=0 end=25 increment=5)))
yaxisopts=(display=(tickvalues) reverse=true griddisplay=on
linearopts=(tickvaluesequence=(start=0 end=70 increment=10)));
histogram mpg_highway / orient=horizontal binstart=0 binwidth=_binwidth binaxis=false
fillattrs=graphdata2 datatransparency=0.3;
endlayout;
endcell;
endlayout;
endgraph;
end;
run;
ods graphics / reset width=5in height=3in imagename='MirrorHistogramHorz';
proc sgrender data=sashelp.cars template=MirrorHistogramHorz;
dynamic _binwidth=2;
run;
/*--MirrorHistograms-Vertical--*/
proc template;
define statgraph MirrorHistogramVert;
dynamic _binwidth;
begingraph;
entrytitle 'Distribution of Blood Pressure';
layout lattice / columndatarange=union rowgutter=0;
columnaxes;
columnaxis / display=(tickvalues) griddisplay=on
linearopts=(tickvaluesequence=(start=40 end=300 increment=20) tickvaluepriority=true);
endcolumnaxes;
layout overlay / walldisplay=none xaxisopts=(griddisplay=on)
xaxisopts=(griddisplay=on)
yaxisopts=(griddisplay=on display=(tickvalues label)
linearopts=(tickvaluesequence=(start=5 end=20 increment=5) tickvaluepriority=true));
histogram systolic / binstart=40 binwidth=_binwidth binaxis=false
fillattrs=graphdata1 datatransparency=0.3;
entry halign=right 'Systolic' / valign=top;
endlayout;
layout overlay / walldisplay=none
yaxisopts=(reverse=true griddisplay=on display=(tickvalues label)
linearopts=(tickvaluesequence=(start=5 end=20 increment=5) tickvaluepriority=true))
xaxisopts=(griddisplay=on);
histogram diastolic / binstart=40 binwidth=_binwidth binaxis=false
fillattrs=graphdata2 datatransparency=0.3;
entry halign=right 'Diastolic' / valign=bottom;
endlayout;
endlayout;
endgraph;
end;
run;
ods graphics / reset width=5in height=3in imagename='MirrorHistogramVert';
proc sgrender data=sashelp.heart template=MirrorHistogramVert;
dynamic _binwidth=5;
run;
/*--Overlay Histograms--*/
ods graphics / reset width=5in height=3in imagename='OverlayHistogramCars';
proc sgplot data=sashelp.cars;
title 'Mileage Distribution';
histogram mpg_city / binstart=0 binwidth=2 transparency=0.5;
histogram mpg_highway / binstart=0 binwidth=2 transparency=0.5;
xaxis display=(nolabel);
yaxis grid;
keylegend / location=inside position=topright across=1;
run;
ods graphics / reset width=5in height=3in imagename='OverlayHistogramHeart';
proc sgplot data=sashelp.heart;
title 'Distribution of Blood Pressure';
histogram diastolic / binstart=50 binwidth=5 transparency=0.5;
histogram systolic / binstart=50 binwidth=5 transparency=0.5;
xaxis display=(nolabel);
yaxis grid;
keylegend / location=inside position=topright across=1;
run;
data ThreeVars;
drop i;
do i=1 to 100;
x=rannor(2);
y=3+rannor(2);
z=5+rannor(2);
output;
end;
run;
ods graphics / reset attrpriority=color width=5in height=3in imagename='OverlayHistogram_3';
proc sgplot data=ThreeVars nocycleattrs noautolegend;
title 'Comparative Histograms';
histogram x / transparency=0.5 binstart=-3 binwidth=0.25 fillattrs=graphdata1 name='x';
density x / type=kernel lineattrs=graphdata1;
histogram y / transparency=0.5 binstart=-3 binwidth=0.25 fillattrs=graphdata2 name='y';
density y / type=kernel lineattrs=graphdata2;
histogram z / transparency=0.5 binstart=-3 binwidth=0.25 fillattrs=graphdata3 name='z';
density z / type=kernel lineattrs=graphdata3;
xaxis display=(nolabel);
yaxis grid offsetmin=0;
keylegend 'x' 'y' 'z' / location=inside position=topright across=1;
run;