Example Program and Statement Details

Example Graph

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

Example Program

proc template;
  define statgraph scatterplot;
    begingraph; 
      entrytitle "Height and Weight by Sex"; 
      layout overlay; 	 
        scatterplot x=height y=weight / 
          group=sex name="scatter" datalabel=name;
        discretelegend "scatter";
      endlayout;	
    endgraph;
  end;
run;

proc sgrender data=sashelp.class template=scatterplot;
run;

Required Arguments

X=column | expression
specifies the column for the X values.
Y=column | expression
specifies the column for the Y values.

Options

Statement Option
Description
Specifies a style element to be used with the MARKERCOLORGRADIENT= option.
Specifies a column for marker labels.
Specifies the color and font attributes of the data labels.
Specifies the degree of the transparency of the markers, data labels, and error bars, when displayed.
Specifies an amount to offset all markers from discrete X values, or discrete Y values, or both.
specifies the attributes of any error bars associated with the data points.
Specifies a column that indicates a frequency count for each observation of the input data object.
Creates a separate marker type for each unique group value of the specified column.
Specifies indices for mapping marker attributes (color and symbol) to one of the GraphData1 - GranphDataN style elements.
Specifies the attributes of the data markers.
Specifies a column that defines strings to be used instead of marker symbols.
Specifies the color and font attributes of the marker character specified on the MARKERCHARACTER= option.
Specifies the column that is used to map marker colors to a continuous gradient.
Assigns a name to a plot statement for reference in other template statements.
Specifies that the data columns for this plot be used for determining default axis features.
Specifies whether to reverse a gradient defined by the COLORMODEL= option.
Specifies roles for information defined by data columns.
Specifies the information to display when the cursor is positioned over the scatter points.
Specifies display formats for information defined by roles.
Specifies display labels for information defined by roles.
Specifies an HTML page to display when a point is selected.
Specifies whether data are mapped to the primary X (bottom) axis or the secondary X2 (top) axis.
Specifies values for the lower endpoints on the X error bars.
Specifies values for the upper endpoints on the X error bars.
Specifies whether data are mapped to the primary Y (left) axis or the secondary Y2 (right) axis.
Specifies values for the lower endpoints on the Y error bars.
Specifies values for the upper endpoints on the Y error bars.
COLORMODEL=style-element
specifies a style element to be used with the MARKERCOLORGRADIENT= option.
Default: The ThreeColorAltRamp style element.
style-element
Name of a style element. The style element should contain these style attributes:
STARTCOLOR color for the smallest data value of the column that is specified on the MARKERCOLORGRADIENT= option
NEUTRALCOLOR color for the midpoint of the range of the column that is specified on the MARKERCOLORGRADIENT= option
ENDCOLOR color for the highest data value of the column that is specified on the MARKERCOLORGRADIENT= option
Interaction: For this option to take effect, the MARKERCOLORGRADIENT= option must also be specified.
The REVERSECOLORMODEL= option can be used to reverse the start and end colors of the ramp assigned to the color model.
DATALABEL=column | expression
specifies a column for marker labels. The label positions are adjusted to prevent them from overlapping.
scatter plot with marker labels
Default: no default
Interaction: If a numeric column is specified and the column has no format, a BEST6. format is applied.
Interaction: This option is ignored if the MARKERCHARACTER= option is used, which displays labels instead of the markers.
DATALABELATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the data labels. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default:
  • For non-grouped data, the GraphDataText style element.
  • For grouped data, the GraphData1:ContrastColor - GraphDataN:ContrastColor style references.
Interaction: For this option to take effect, the DATALABEL= option must also be specified.
Interaction: This option is ignored if the MARKERCHARACTER= option is specified.
DATATRANSPARENCY=number
specifies the degree of the transparency of the markers, data labels, and error bars, when displayed.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
DISCRETEOFFSET=number
specifies an amount to offset all markers from X values for a discrete X axis, or from Y values for a discrete Y axis. If both axes are discrete, the offset applies to both axes.
Note: This feature is for the third maintenance release of SAS 9.2 and later.
Default: 0 (no offset, all markers are centered on the X values for a discrete X axis, or on the Y values for a discrete Y axis)
Range: -0.5 to +0.5, where .5 represents half the distance between discrete ticks. A positive offset is to the right on discrete X values and up on discrete Y values. If the layout’s axis options set REVERSE=TRUE, the offset direction is also reversed.
Details: This feature is useful for graphing multiple response variables side by side on a common axis. By default within an overlay-type layout, if a SCATTERPLOT is used with other plots with a discrete axis, the markers are centered on the discrete X values, or discrete Y values, or both. Depending on the data, the markers might be superimposed over other graph data. The following code fragment shows the default positioning when a SCATTERPLOT is used with a BOXPLOT:
layout overlay / cycleattrs=true
     xaxisopts=(type=discrete);

  scatterplot x=age y=weight;
  boxplot x=age y=weight;

endlayout;
Scatter Plot with Box Plot, No Offset
To avoid superimposed plots, you can assign a different offset to each plot statement:
layout overlay / cycleattrs=true
    	xaxisopts=(type=discrete);
  scatterplot x=age y=weight /
    discreteoffset=0.2;
  boxplot x=age y=weight /
    discreteoffset=-0.2;
endlayout;
Scatter Plot with Box Plot, Offset=0.2
ERRORBARATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the error bars that are associated with the data points. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default:
  • For non-grouped data, the GraphError style element.
  • For grouped data, the LineStyle and LineThickness attributes of the GraphError style element and the ContrastColor attribute of the GraphData1 - GraphDataN style elements. (The LineStyle does not apply to the "serif" parts of the error bars.)
Interaction: For this option to take effect, error bars must be displayed by the XERRORLOWER=, XERRORUPPER=, YERRORLOWER=, or YERRORUPPER= options.
FREQ=numeric-column | expression
specifies a column that indicates a frequency count for each observation of the input data object. If n is the value of the FREQ variable for a given observation, then that observation is plotted n times.
Default: Each observation is plotted once.
Restriction: If the value of the numeric-column is missing or is less than 1, the observation is not used in the analysis. If the value is not an integer, only the integer portion is used.
GROUP=column | expression
creates a separate marker type for each unique group value of the specified column.
Default: Each distinct group value might be represented in the graph by a different combination of color and marker symbol. Markers vary according to the ContrastColor and MarkerSymbol attributes of the GraphData1 - GraphDataN style elements.
Interaction: The group values are mapped in the order of the data, unless the INDEX= option is used to alter the default sequence of markers and colors.
Interaction: The marker size is set by the MARKERATTRS= option.
Interaction: If the MARKERCHARACTER= and MARKERCOLORGRADIENT= options are used, their settings override the group settings for marker symbol and marker color.
Interaction: The representations that are used to identify the groups can be overridden. For example, each distinct group value is represented by a different marker symbol, but the MARKERATTRS= ( SYMBOL= marker ) option could be used to assign the same symbol to all of the plot’s marker symbols, letting marker color indicate group values. Likewise, MARKERATTRS= ( COLOR= color ) could be used to assign the same color to all markers, letting marker symbol indicate group values.
INDEX=positive-integer-column | expression
specifies indices for mapping marker attributes (color and symbol) to one of the GraphData1 - GranphDataN style elements.
Default: no default
Interaction: For this option to take effect, the GROUP= option must also be specified.
Interaction: All of the indexes for a specific group value must be the same. Otherwise, the results are unpredictable.
Interaction: If this option is not used, then the group values are mapped in the order of the data.
Interaction: If the MARKERCHARACTER= and MARKERCOLORGRADIENT= options are used, their settings override the group settings for marker symbol and marker color.
Interaction: The index values are 1-based indices. For the style elements GraphData1 - GraphDataN, if the index value is greater than N, then a modulo operation remaps that index value to a number less than N to determine which style element to use.
Discussion: Indexing can be used to collapse the number of groups that are represented in a graph. For more information, see Remapping Groups for Grouped Data.
LEGENDLABEL= "string"
specifies a label to be used in a legend.
Default: The Y-variable label. If a label is not defined, the Y-variable name.
Interaction: If the GROUP= option is specified, this option is ignored.
MARKERATTRS=style-element | style-element (marker-options) | (marker-options)
specifies the attributes of the data markers. See General Syntax for Attribute Options for the syntax on using a style-element and Marker Options for available marker-options.
Default:
  • For non-grouped data, the GraphDataDefault style element.
  • For grouped data, the MarkerSymbol and ContrastColor attributes of the GraphData1 - GraphDataN style elements, and the GraphDataDefault:MarkerSize style reference.
Interaction: If the MARKERCOLORGRADIENT= option is specified, this option’s COLOR= setting is ignored.
Interaction: If the MARKERCHARACTER= option is specified, its SYMBOL= and WEIGHT= settings are ignored.
MARKERCHARACTER=column | expression
specifies a column that defines strings to be used instead of marker symbols.
scatter plot with strings instead of markers
Default: no default
Interaction: This option overrides the DATALABEL= option.
Interaction: If the GROUP= option is also used, color is displayed for a DISCRETE legend, but the character is not displayed in the legend.
If the GROUP= option is also specified, the same colors are applied to the text strings as would have been applied to markers.
If a numeric column is used, its values are converted to strings using the format associated with the column or BEST6. if no format is defined.
Each string is centered horizontally and vertically at the data point. The data point positions are not adjusted to prevent text overlap.
MARKERCHARACTERATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the marker character specified on the MARKERCHARACTER= option. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default:
  • For non-grouped data, the GraphDataText style element.
  • For grouped data, GraphData1:ContrastColor - GraphDataN:ContrastColor style references.
Interaction: For this option to take effect, the MARKERCHARACTER= option must also be used.
When the GROUP= option is also specified, each distinct group value might be represented by a different color (depending on the ODS style setting or the setting on the INDEX= option). The marker character that is associated with the group is assigned the group color. This option’s COLOR= suboption can be used to specify a single color for all marker characters in a graph, without affecting items that have the group color, such as error bars and marker symbols.
MARKERCOLORGRADIENT=numeric-column | expression
specifies the column that is used to map marker colors to a continuous gradient.
Default: no default
Restriction: To display a legend with this option in effect, you must use a CONTINUOUSLEGEND statement, not a DISCRETELEGEND statement.
Interaction: This option overrides the COLOR= setting of the MARKERATTRS= or MARKERCHARACTERATTRS= option.
This option can be used to add a second response variable to an analysis. For example, in an analysis of weight by height, an age column might be specified by the MARKERCOLORGRADIENT= option so that the change in the gradient color of the markers reflects the change in age.
scatter plot that maps a color gradient to markers
By default, the color range is determined by the ThreeColorAltRamp style element. The COLORMODEL= option allows a different color range to be used.
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 marker symbols 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
Restriction: This option is ignored if the plot is placed under a GRIDDED or LATTICE layout block.
Details: This option is needed only when two or more plots within an overlay-type 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
ROLENAME=( role-name-list )
specifies user-defined roles for information contained in data columns.
Default: no default
(rolename-list)
a blank-separated list of rolename = column pairs.
For example, ROLENAME= ( TIP1=OBS ) assigns the column OBS to the user-defined role TIP1.
Requirement: The role names that you choose must be unique and different from the pre-defined roles X, Y, DATALABEL, MARKERCHARACTER, MARKERCOLORGRADIENT, XERRORLOWER, XERRORUPPER, YERRORLOWER, YERRORUPPER, GROUP, and INDEX.
Interaction: For this option to take effect, the TIP= option must also be used.
This option provides a way to add to the data columns that appear in tooltips specified by the TIP= option.
TIP=(role-list)
specifies the information to display when the cursor is positioned over the scatter points. If this option is used, it replaces all the information displayed by default. Roles for columns that do not contribute to the scatter plot can be specified along with roles that do.
Default: The columns assigned to these roles are automatically included in the tooltip information: X, Y, DATALABEL, MARKERCHARACTER, MARKERCOLORGRADIENT, XERRORLOWER, XERRORUPPER, YERRORLOWER, YERRORUPPER, FREQ, and GROUP.
(role-list)
an ordered, blank-separated list of unique SCATTERPLOT and user-defined roles. SCATTERPLOT roles include X, Y, DATALABEL, MARKERCHARACTER, MARKERCOLORGRADIENT, XERRORLOWER, XERRORUPPER, YERRORLOWER, YERRORUPPER, GROUP, and INDEX.
User-defined roles are defined with the ROLENAME= option.
The following example displays tooltips for the columns assigned to the roles X, XERRORUPPER and XERRORLOWER, as well as the column OBS, which is not assigned to any pre-defined ScatterPlot role. The OBS column must first be assigned a role.
  ROLENAME=(TIP1=OBS)
  TIP= (TIP1 X XERRORUPPER XERRORLOWER)
Requirement: To generate tooltips, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
The labels and formats for the TIP variables can be controlled with the TIPLABEL= and TIPFORMAT= options.
TIPFORMAT=(role-format-list)
specifies display formats for tip columns.
Default: The column format of the variable assigned to the role or BEST6. if no format is assigned to a numeric column.
(role-format-list)
a list of rolename = format pairs separated by blanks.
  ROLENAME=(TIP1=OBS)
  TIP=(TIP1 X XERRORUPPER XERRORLOWER)
  TIPFORMAT=(XERRORUPPER=5.3 XERRORLOWER=5.3) 
Requirement: Columns must be assigned to the roles for this option to have any effect. See the ROLENAME= option.
This option provides a way to control the formats of columns that appear in tooltips. Only the roles that appear in the TIP= option are used.
TIPLABEL=(role-label-list)
specifies display labels for tip columns.
Default: The column label or column name of the variable assigned to the role.
(role-label-list)
a list of rolename = "string" pairs separated by blanks.
   ROLENAME=(TIP1=PCT) 
   TIP=(TIP1 X XERRORUPPER XERRORLOWER)
   TIPLABEL=(XERRORUPPER="1 STD ERROR"
   XERRPRLOWER="-1 STD ERROR")
Requirement: Columns must be assigned to the roles for this option to have any effect. See the ROLENAME= option.
This option provides a way to control the labels of columns that appear in tooltips. Only the roles that appear in the TIP= option are used.
URL=character-column
specifies an HTML page to display when a point is selected.
Default: no default
character-column
each value of the column must be a valid HTML page reference (HREF). For example, http://www.sas.com/technologies/analytics/index.html.
Requirement: To generate selectable markers, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
The URL value can be blank for some X and Y pairs, meaning that no action is taken when the corresponding point is selected. The URL value can be the same for any X and Y pairs. In that case, the same action is taken when the points for those X and Y pairs are selected.
XAXIS=X | X2
specifies whether data are mapped to the primary X (bottom) axis or to the secondary X2 (top) axis.
Default: X
Interaction: This option is ignored if the X= argument is not specified.
Interaction: The overall plot specification and the layout type determine the axis display for the specified axis. For more information, see How Axis Features are Determined.
XERRORLOWER=numeric-column | expression
specifies values for the lower endpoints on the X error bars.
Default: The lower segment of the error bars is not drawn.
The values are actual values, not relative values.
The appearance of the error bars is controlled by the ERRORBARATTRS= option.
XERRORUPPER=numeric-column | expression
specifies values for the upper endpoints on the X error bars.
Default: The upper segment of the error bars is not drawn.
The values are actual values, not relative values.
The appearance of the error bars is controlled by the ERRORBARATTRS= option.
YAXIS=Y | Y2
specifies whether data are mapped to the primary Y (left) axis or to the secondary Y2 (right) axis.
Default: Y
Interaction: This option is ignored if the Y= argument is not specified.
Interaction: The overall plot specification and the layout type determine the axis display for the specified axis. For more information, see How Axis Features are Determined.
YERRORLOWER=numeric-column | expression
specifies values for the lower endpoints on the Y error bars.
Default: The lower segment of the error bars is not drawn.
The values are actual values, not relative values.
The appearance of the error bars is controlled by the ERRORBARATTRS= option.
YERRORUPPER=numeric-column | expression
specifies values for the upper endpoints on the Y error bars.
Default: The upper segment of the error bars is not drawn.
The values are actual values, not relative values.
The appearance of the error bars is controlled by the ERRORBARATTRS= option.