/*--Transpose grouped data into multi-variable--*/ data multiVar; keep mpg_usa mpg_asia mpg_eur; merge sashelp.cars(where=(origin="USA") rename=(mpg_city=mpg_usa)) sashelp.cars(where=(origin="Asia") rename=(mpg_city=mpg_asia)) sashelp.cars(where=(origin="Europe") rename=(mpg_city=mpg_eur)); run; /*proc print; run;*/ /*--Histogram and density--*/ ods listing gpath=&gpath; ods graphics / reset width=5in height=3in imagename='HistogramDensity'; title 'Mileage Distribution'; proc sgplot data=sashelp.cars; histogram mpg_city; density mpg_city / type=normal legendlabel='Normal' lineattrs=(pattern=solid); density mpg_city / type=kernel legendlabel='Kernel' lineattrs=(pattern=solid); keylegend / location=inside position=topright across=1; xaxis display=(nolabel); run; /*--Comparative Normal Density--*/ ods listing gpath=&gpath; ods graphics / reset width=5in height=3in imagename='ComparativeNormal'; title 'Mileage Distribution by Origin'; proc sgplot data=multiVar; density mpg_usa / legendlabel='USA' lineattrs=(pattern=solid); density mpg_asia / legendlabel='Asia' lineattrs=(pattern=solid); density mpg_eur / legendlabel='Europe' lineattrs=(pattern=solid); keylegend / location=inside position=topright across=1; xaxis display=(nolabel); run; /*--Comparative Kernel Density--*/ ods graphics / reset width=5in height=3in imagename='ComparativeKernel'; title 'Mileage Distribution by Origin'; proc sgplot data=multiVar; density mpg_usa / type=kernel legendlabel='USA' lineattrs=(pattern=solid); density mpg_asia / type=kernel legendlabel='Asia' lineattrs=(pattern=solid); density mpg_eur / type=kernel legendlabel='Europe' lineattrs=(pattern=solid); keylegend / location=inside position=topright across=1; xaxis display=(nolabel); run; /*--Multi Histogram--*/ ods listing gpath=&gpath; ods graphics / reset width=5in height=3in imagename='MultiHistogram'; title 'Distribution of Blood Pressure'; proc sgplot data=sashelp.heart; histogram systolic / fillattrs=graphdata1 name='s' legendlabel='Systolic' transparency=0.5; histogram diastolic / fillattrs=graphdata2 name='d' legendlabel='Diastolic' transparency=0.5; keylegend 's' 'd' / location=inside position=topright across=1; xaxis display=(nolabel); run;