%let gpath='C:\';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--Subset data set--*/
data cars;
set sashelp.cars(where=(type ne 'Hybrid'));
run;
/*--Basic graph--*/
ods graphics / reset width=5in height=3in imagename='Graph_1';
proc sgplot data=cars;
vbar origin / response=mpg_city group=type groupdisplay=cluster stat=mean ;
xaxis display=(nolabel);
title 'Mileage by Origin and Type';
run;
/*--Map Type values to 1-5 in MyType--*/
data newcars;
set cars;
if type='Wagon' then mytype=1;
else if type='Sports' then mytype=2;
else if type='SUV' then mytype=3;
else if type='Truck' then mytype=4;
else if type='Sedan' then mytype=5;
run;
/*--sort by MyType--*/
proc sort data=newcars out=sortcars;
by mytype;
run;
/*--Make control data set for format--*/
data myfmt;
set sortcars;
by mytype;
if first.mytype then do;
fmtname='typefmt';
start=mytype;
label=type;
drop type;
output;
end;
run;
/*--Create format--*/
proc format cntlin=myfmt;
run;
/*--Graph with ordered type values--*/
ods graphics / reset width=5in height=3in imagename='Graph_2';
proc sgplot data=newcars;
vbar origin / response=mpg_city group=mytype
groupdisplay=cluster stat=mean;
keylegend /title='Type';
xaxis display=(nolabel);
format mytype typefmt.;
title 'Mileage by Origin and Type';
run;