* Name: 3dplotscatter.SAS * * Title: Produces a 3d scatterplot with observed values * * %scatter3d(data=, var=, group=, min=, max=, n=); * *-------------------------------------------------------------------* * Phil Wood email: Phillipkwood@yahoo.com * * Created: Oct 2007 * * Version: 1.0 * *-------------------------------------------------------------------*/ %macro scatter(data=_LAST_, var=_NUMERIC_, /* variables to plot */ id=, symbols=square plus circle diamond X up down star, colors=BLACK RED GREEN BLUE BROWN YELLOW ORANGE PURPLE,out=_paint_ ); /*Make a data set of possible values for the predicted regression surface*/ data grid; sales=.; do &x=&minx to &maxx by 1; do &y=&miny to &maxy by .2; output; end; end; data large;set &data grid; proc reg data=large; model &z=&x &y; output out=results p=yhat r=residual rstudent=rstudent h=hatvalue; id id; data resultsp;set results;if &z=.; &z=yhat; proc g3d data=resultsp; plot &y*&x=&z/rotate=0 to 360 by 30 ctop=red cbottom=green xticknum=3 yticknum=3 ; title 'predicted response surface';run; data fit;set results end=last;if sales=.; sales=yhat; if last; * Create two 'dummy' observations with the min and max x, y and z values ; &x=&minx; &y=&miny; &z=&minz; colorval='white'; shapeval='point'; * 'Hide' the 'dummy' points ; output; &x=&maxx; &y=&maxy; &z=&maxz;colorval='white'; shapeval='point'; * 'Hide' the 'dummy' points ; output; run; data needles;set results;if &y^=.; length caseid text $12; caseid=' '; if abs(rstudent)>tinv(.9,&n-3,0) |hatvalue>2*3/&n then caseid=put(id,3.); xsys='2';ysys='2';zsys='2'; y=&y;x=&x; z=yhat;function='MOVE ';output; if residual>0 then do; line=1;color='BLACK';position='2'; end; else do; line=1;color='RED';position='8'; end; z=&z;function='DRAW ';output; function='SYMBOL';text='+';output; function='LABEL';text=caseid;output; proc g3d data=fit; plot &y*&x=&z/rotate=0 to 360 by 90 ctop=red cbottom=green xticknum=3 yticknum=3 anno=needles grid; title 'plot of estimated regression surface';run; data fitresult;set fit resultsp; proc g3d data=fitresult; plot income*children=sales /rotate=0 to 360 by 60 ctop=yellow cbottom=blue xticknum=3 yticknum=3 anno=needles grid; title 'plot of estimated regression surface refere to figure 6.7';run; %mend;