## Friday, April 29, 2011

### Lab2A 3D clustered column plots realized in SAS

This is an example from the TA textbook <Essential of Modern Business Statistics>, the graph is on page 65. Here I try to draw this graph with SAS. The original Excel data is: restaurant data.

The original graph is generated from Excel with clustered column plot. Looks like:

Now I try to plot it with SAS. The job is not finished. Still to make improvement with it.

proc import datafile="c:\sasdata\lab2a.xls"
out=restaurant
dbms=excel replace;
sheet="restaurant";
getnames=yes;
run;

proc datasets;
modify restaurant;
rename quality_rating=qty_rate meal_price____=meal_p;
run;

data restaurant;
set restaurant;
if 10 <= meal_p < 19 then meal='A';
else if 19 <= meal_p < 29 then meal='B';
else if 29 <= meal_p < 39 then meal='C';
else  meal='D';
run;

proc sort data=restaurant;
by qty_rate meal;
run;

data restnew;
set restaurant;
by qty_rate meal;
retain i;
if first.meal or first.meal then i=1;
else i=i+1;
if last.qty_rate or last.meal then output;
run;

proc print data=restnew;
run;

goptions device=png;
goptions noborder;

goptions gunit=pct htitle=6 ftitle="albany amt/bold" htext=4.25 ftext="albany amt/bold";

axis1 label=none value=none
axis2 label=(a=90 'Cardinarity of Each Subgroup') order=(0 to 70 by 10) minor=(number=1) offset=(0,0);
axis3 label=('Rate') offset=(7,5);

pattern1 v=solid color=cx9999ff;  /* light blue */
pattern2 v=solid color=cx993366;  /* purplish */
pattern3 v=solid color=cxffffcc;  /* pale yellow */
pattern4 v=solid color=green;  /* green */

proc gchart data=restnew;
vbar3d meal / discrete
type=sum sumvar=i
group=qty_rate
cframe=white /* otherwise the background/frame for 3d bar charts is dark gray */
space=0
gspace=8
subgroup=meal /* this controls the coloring */
maxis=axis1 /* midpoint axis */
raxis=axis2 /* response/numeric axis */
gaxis=axis3 /* group axis */
autoref clipref cref=graycc
nolegend
coutline=black
des="" name="&name"
run;

quit;

The graph is as below:

( Thanks for help from Robert Allison )