Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Needle Plot Graph

Example Program

proc template;
  define statgraph needleplot;
    begingraph; 
      entrytitle "IBM Stock Trend"; 
      layout overlay; 	 
        needleplot x=date y=close /
          baselineintercept=80 lineattrs=(color=blue);
      endlayout;	
    endgraph;
  end;
run;

proc sgrender data=sashelp.stocks template=needleplot;
  where stock="IBM" and date > "31dec1999"d;
run;

Statement Summary

In the NEEDLEPLOT statement, the X variable can specify character or numeric values. The Y variable must specify numeric values. For character columns, the X-axis is always of TYPE=DISCRETE. For numeric columns, the X-axis is of TYPE=LINEAR by default.
The Y-axis is of TYPE=LINEAR by default.

Required Arguments

X=column | expression
specifies a column or expression for the X values.
Y=numeric-column | expression
specifies a numeric column or numeric expression for the Y values.

Options

Statement Option
Description
Specifies the Y-intercept for the baseline.
Specifies labels at the data points.
Specifies the color and font attributes of the data labels.
Specifies the degree of the transparency of the needles and the markers, if displayed.
Specifies whether to display needle lines with or without markers.
Creates a separate needle plot for each unique group value of the specified column.
Specifies indices for mapping needle attributes (color, marker symbol, and line pattern) to one of the GraphData1 - GranphDataN style elements.
Specifies a label for use in a legend.
Specifies the properties of the needles.
Specifies the attributes of the data markers.
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 roles for information defined by data columns.
Specifies the information to display when the cursor is positioned over a needle line or marker.
Specifies display formats for information defined by roles.
Specifies display labels for information defined by roles.
Specifies an HTML page to display when a needle line is selected.
Specifies whether data are mapped to the primary X (bottom) axis or the secondary X2 (top) axis.
Specifies whether data are mapped to the primary Y (left) axis or the secondary Y2 (right) axis.
BASELINEINTERCEPT=number | RELATIVE
specifies the Y-intercept for the baseline.
Default: 0
number
The Y-intercept value to use for the baseline.
RELATIVE
The baseline is placed at the Y-axis tick mark closest to the minimum of the range for the needle data points.
DATALABEL=column
specifies labels at the data points.
Default: no default
The position of the labels is adjusted to prevent the labels from overlapping.
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 GraphValueText style element.
  • For grouped data, the GraphData1:ContrastColor - GraphDataN:ContrastColor style references.
Interaction: For this option to have any effect, the DATALABEL= option must also be specified.
DATATRANSPARENCY=number
specifies the degree of the transparency of the needles and markers, if displayed.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
DISPLAY=STANDARD | ALL | display-options
specifies whether to display needle lines with or without markers.
Default: STANDARD
STANDARD
displays needle lines without markers.
ALL
displays needle lines with markers.
(display-options)
a list of options, enclosed in parentheses. Currently only the following option is available:
MARKERS—displays needle lines with markers
Use the MARKERATTRS= and LINEATTRS= options to control the appearance of the line and markers.
GROUP=column | expression
creates a distinct set of needles, markers, and data labels 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, line pattern, and marker symbol. These vary according to the ContrastColor, LineStyle, 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 marker symbols, colors, and line patterns.
Interaction: The marker size is set by the MARKERATTRS= option.
The representations that are used to identify the groups can be overridden. For example, each distinct group value might be represented by a different line pattern, but the LINEATTRS= ( PATTERN=pattern ) option could be used to assign the same line pattern to all of the plot’s line patterns, letting line color indicate group values. Likewise, LINEATTRS= ( COLOR= color ) could be used to assign the same color to all lines, letting line pattern indicate group values.
INDEX=positive-integer-column
specifies indices for mapping needle attributes (color, marker symbol, and line pattern) to one of the GraphData1 - GranphDataN style elements.
Default: no default
Interaction: For this option to have any 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: The index values are 1-based indices. For the style elements in 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 for use 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.
LINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the needles for 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 GraphDataDefault style element.
  • For grouped data, the ContrastColor, LineStyle and LineThickness attributes of the GraphData1 - GraphDataN style elements.
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, MarkerSize, and ContrastColor attributes of the GraphData1 - GraphDataN style elements.
Interaction: The DISPLAY= option must display markers for this option to have any effect.
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, marker symbols, and line patterns between the graph and the legend.
PRIMARY=boolean
specifies that the data columns for this plot 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
ROLENAME=( role-name-list )
specifies user-defined roles for information contained in data columns.
Default: no default
(role-name-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, INDEX, and GROUP.
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 a needle line or marker. If this option is used, it replaces all the information displayed by default. Roles for columns that do not contribute to the needle 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, and GROUP.
(role-list)
an ordered, blank-separated list of unique NEEDLEPLOT and user-defined roles. NEEDLEPLOT roles include X, Y, DATALABEL, and GROUP.
User-defined roles are defined with the ROLENAME= option.
The following example displays tooltips for the columns assigned to the roles X and Y as well as the column OBS, which is not assigned to any pre-defined NeedlePlot role. The OBS column must first be assigned a role.
  ROLENAME=(TIP1=OBS)
  TIP= (TIP1 X Y)
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.
Interaction: 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 Y)
  TIPFORMAT=(TIP1=4.) 
Requirement: 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. Columns must be assigned to the roles for this option to have any effect. See the ROLENAME= option.
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=OBS) 
   TIP=(TIP1 X Y)
   TIPLABEL=(TIP1="Observation #")
Requirement: 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. Columns must be assigned to the roles for this option to have any effect. See the ROLENAME= option.
URL=character-column
specifies an HTML page to display when a needle or marker 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 needles, 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 needle or marker 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 needle or marker is selected for those X and Y pairs.
XAXIS=X | X2
specifies whether data are mapped to the primary X (bottom) axis or to the secondary X2 (top) axis.
Default: X
Interaction: The overall plot specification and the layout type determine the axis display. For more information, see How Axis Features are Determined.
YAXIS=Y | Y2
specifies whether data are mapped to the primary Y (left) axis or to the secondary Y2 (right) axis.
Default: Y
Interaction: The overall plot specification and the layout type determine the axis display. For more information, see How Axis Features are Determined.