Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Surface Plot

Example Program

proc template;
  define statgraph surfaceplotparm;
    begingraph;
      entrytitle "Surface Plot of Lake Bed";
      layout overlay3d / cube=false;
        surfaceplotparm x=length y=width z=depth /
          reversecolormodel=true
          surfacecolorgradient=depth
          colormodel=twocoloraltramp;
      endlayout;
    endgraph;
  end;

/* create gridded data for surface 
 * proc g3grid is a sas/graph procedure */
proc g3grid data=sashelp.lake out=gridded;
  grid width*length = depth / naxis1=75 naxis2=75;
run;

proc sgrender data= gridded template=surfaceplotparm;
run;

Statement Summary

The SURFACEPLOTPARM statement assumes that the Z response values have been provided for a uniform X-Y grid. Missing Z values leave a “hole” in the surface. The observations in the input data set should form an evenly spaced grid of horizontal (X and Y) values and one vertical (Z) value for each of these combinations. The observations should be in sorted order of Y and X to obtain an accurate graph.
The G3GRID procedure (requires a SAS/GRAPH license) can be used to interpolate the necessary values to produce a data set with nonmissing Z values for every combination of X and Y. The G3GRID procedure can also smooth data with spline interpolations. For further details, see the documentation for PROC G3GRID in the SAS/GRAPH: Reference.
Using PROC G3GRID, the following code performs a Spline interpolation and generates this figure:
surface plot with spline interpolation
data nums;
  do i=1 to 30;
     X=10*ranuni(33)-5;
     Y=10*ranuni(35)-5;
     Z=sin(sqrt(x*x+y*y));
     output;
  end;
run; 
proc g3grid data=nums out=gridded;
  grid y*x=z / spline 
               axis1=-5 to 5 by .1
               axis2=-5 to 5 by .1;
run;
proc sort data=gridded; by y x; run;

proc template;
  define statgraph g3grid_surface; 
   begingraph;
    entrytitle "Spline Interpolation";
    layout overlay3d;
      surfaceplotparm x=x y=y z=z / 
        surfacetype=fill;
    endlayout; 
   endgraph;
  end;
run;

proc sgrender data=gridded template=g3grid_surface;
run;
The KDE procedure can produce an output data set of gridded X-Y values where the Z value is computed to be a Kernel Density Estimate of the distribution of X and Y. For further details, see the documentation for PROC KDE in the SAS/STAT user’s guide.
Using PROC KDE on the nums data generated in the previous example, the following code computes a Kernel Density Estimate and generates this figure:
surface plot with kernel density estimate
/* use the nums data generated in the previous example */
proc kde data=nums;
  bivar x y / ngrid=100
    out=binned(rename=(value1=X value2=Y));
run;
proc sort data=binned; by y x;
  label x="X" y="Y";
run;

proc template;
  define statgraph kde_surface;
   begingraph;
     entrytitle "Kernel Density Estimate";
     layout overlay3d;
       surfaceplotparm x=x y=y z=density /
         surfacetype=fill;
     endlayout;
   endgraph;
  end;
run;

proc sgrender data=binned template=kde_surface;
run;
The SURFACEPLOTPARM does not support the tooltips that are enabled by the IMAGEMAP= option in the ODS GRAPHICS statement.

Required Arguments

X=numeric-column | expression
specifies the X coordinates of the grid.
Y=numeric-column | expression
specifies the Y coordinates of the grid.
Z=numeric-column | expression
specifies the height of response values.
Note: The input data should be sorted by both 1) the Y column and 2) the X column. The sort direction for Y should be ascending. The sort direction of X be either ascending or descending.

Options

Statement Option
Description
Specifies a style element that is used to determine the colors of the contour lines or filled areas.
Specifies the degree of the transparency of the surface.
Specifies the appearance of the filled surface or the wire-frame mesh.
Specifies a label for a legend.
Assigns a name to a plot statement for reference in other template statements.
Specifies that the data columns for this plot and the plot type be used for determining default axis features.
Specifies whether to reverse a gradient defined by the COLORMODEL= option.
Specifies a column that is used to map surface colors to a continuous gradient.
Specifies how the surface is displayed.
COLORMODEL=style-element
specifies a style element that is used to determine gradient surface colors.
Default: The ThreeColorRamp style element.
style-element
Name of a style element. The style element should contain these style attributes:
STARTCOLOR specifies a color for the smallest data value of the SURFACECOLORGRADIENT variable
NEUTRALCOLOR specifies a color for the midpoint of the range Of the SURFACECOLORGRADIENT variable
ENDCOLOR specifies a color for the highest data value of the SURFACECOLORGRADIENT variable
Interaction: For this option to have any effect, the SURFACECOLORGRADIENT= option must also be used.
The REVERSECOLORMODEL= option can be used to reverse the start and end colors of the ramp assigned to the color model.
DATATRANSPARENCY=number
specifies the degree of the transparency of the surface.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the color of the filled surface or the wire-frame mesh. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
Default: The GraphDataDefault:Color style reference.
Interaction: The SURFACECOLORGRADIENT= option is ignored if this option is specified.
LEGENDLABEL= "string"
specifies a label for the legend item that is associated with this plot.
Default: The Z-variable label. If a label is not defined, the Z-variable name.
Restriction: This option applies only to an associated DISCRETELEGEND statement.
NAME="string"
assigns a name to a plot statement for reference in other template statements.
Default: no default
Restriction: The string is case sensitive, cannot contain spaces, and must define a unique name within the template.
The specified name is used primarily in legend statements to coordinate the use of colors and line patterns between the graph and the legend.
PRIMARY=boolean
specifies that the data columns for this plot and the plot type be used for determining default axis features.
Default: FALSE
Details: This option is needed only when two or more plots within an OVERLAY3D layout contribute to a common axis. For more information, see When Plots Share Data and a Common Axis.
REVERSECOLORMODEL=boolean
specifies whether to reverse a gradient (color ramp) defined by the COLORMODEL= option.
Default: FALSE
SURFACECOLORGRADIENT=numeric-column
specifies a column that is used to map surface colors to a continuous gradient.
Default: no default
Interaction: This option is ignored if the FILLATTRS= option is specified.
SURFACETYPE=FILLGRID | FILL | WIREFRAME
specifies how the surface is displayed.
Default: FILLGRID
FILLGRID
a filled surface with superimposed grid lines
FILL
a filled surface without grid lines
WIREFRAME
an unfilled surface with grid lines