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 )
一个自己注意的地方:刚开始我用proc format来format meal_price,但是那么做以后不管怎么运行,first.和last.来计数的时候都不对。
ReplyDelete最后找到问题是,format尽管使得data的显示变化了(比如变为ABCD),但是实际上DATA并没有变化。所以得不到想要的group的效果。 最后还是增加了一个变量meal才得到了结果。