proc template; /* surface plot with continuous color ramp */ define statgraph SurfaceTmplt; dynamic _X _Y _Z _Title; /* dynamic variables */ begingraph; entrytitle _Title; /* specify title at run time (optional) */ layout overlay3d; surfaceplotparm x=_X y=_Y z=_Z / /* specify variables at run time */ name="surface" surfacetype=fill colormodel=threecolorramp /* or =twocolorramp */ colorresponse=_Z; continuouslegend "surface"; endlayout; endgraph; end; run; /* sample data: a cubic function of two variables */ %let Step = 0.04; data A; do x = -1 to 1 by &Step; do y = -1 to 1 by &Step; z = x**3 - y**2 - x + 0.5; output; end; end; run; /* plot the surface */ proc sgrender data=A template=SurfaceTmplt; dynamic _X='X' _Y='Y' _Z='Z' _Title="Cubic Surface"; run; /**********************************************************/ /* What can you do if the data are not on a regular grid? You can create a regression model and score the model. */ /**********************************************************/ data IrregData; do i = 1 to 1000; x = rand("Uniform", -1, 1); y = rand("Uniform", -1, 1); z = x**3 - y**2 - x + 0.5; output; end; run; /* For these data, a cubic surface fits the data exactly. Notice that PROC GLM creates a contour plot of the surface. */ proc glm data=IrregData; model z = x | x | x | y | y | y @3; store work.Cubic; /* store the model */ run; /* create an evenly spaced grid of (x,y) points */ %let Step = 0.04; data Grid; do x = -1 to 1 by &Step; do y = -1 to 1 by &Step; output; end; end; run; /* score the model on the grid */ proc plm restore=work.Cubic; score data=Grid out=Pred; run; /* visualize the regression surface */ proc sgrender data=Pred template=SurfaceTmplt; dynamic _X='X' _Y='Y' _Z='Predicted' _Title="Regression Surface"; run;