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 the width of the group clusters as a fraction of the midpoint spacing.
Specifies labels at the data points.
Specifies the color and font attributes of the data labels.
Specifies the location of the data labels relative to the end of the needle lines and markers, if displayed.
Specifies the degree of the transparency of the needle lines and the markers, if displayed.
Specifies an amount to offset all needle lines and markers from discrete X values when graphing multiple response variables side by side on a common axis.
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 whether grouped needle lines are overlaid or clustered around the category midpoints.
Specifies the relative position of the needle lines for clustered group display.
Specifies whether missing values of the group variable are included in the plot.
Specifies indices for mapping needle attributes (color, marker symbol, and line pattern) to one of the GraphData1–GraphDataN style elements.
Specifies a label for a legend.
Specifies the properties of the needle lines.
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 user-defined roles that can be used to display information in the tooltips.
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.
CLUSTERWIDTH= number
specifies the width of the group clusters as a fraction of the midpoint spacing on a discrete axis or a fraction of the minimum interval between adjacent data values on an interval axis.
Default: 0.85
Range: 0.1 (narrowest) to 1 (widest)
Interaction: For this option to take effect, the GROUP= option must also be specified.
DATALABEL=column
specifies labels at the data points.
Default: no data labels are displayed
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.
DATALABELPOSITION = AUTO | TOPRIGHT | TOP | TOPLEFT | LEFT | CENTER | RIGHT | BOTTOMLEFT | BOTTOM | BOTTOMRIGHT
specifies the location of the data labels relative to the end of the needle lines and markers, if displayed.
Default: AUTO
DATATRANSPARENCY=number
specifies the degree of the transparency of the needle lines and markers, if displayed.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
DISCRETEOFFSET=number
specifies an amount to offset all needle lines and markers from discrete X values when graphing multiple response variables side by side on a common axis.
Default: 0 (no offset, all needle lines and markers are centered on the discrete X values)
Range: -0.5 to +0.5, where .5 represents half the distance between discrete ticks. A positive offset is to the right. If the parent layout’s axis options set REVERSE=TRUE, then the offset direction is also reversed.
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 | discrete-attr-var | expression
creates a distinct set of needle lines, markers, and data labels for each unique group value of the specified column.
discrete-attr-var
specifies a discrete attribute variable that is defined in a DISCRETEATTRVAR statement.
Restriction: A discrete attribute variable specification must be a direct reference to the attribute variable. It cannot be set by a dynamic variable.
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.
Interaction: The INCLUDEMISSINGGROUP= option controls whether missing group values are considered a distinct group value.
Tip: 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.
GROUPDISPLAY= OVERLAY | CLUSTER
specifies whether grouped needle lines are overlaid or clustered around the category midpoints on a discrete axis or around the intervals on an interval axis.
Default: OVERLAY
OVERLAY
Needle lines for matching category values are centered on the midpoints and superimposed on each other.
CLUSTER
Needle lines for matching category values are clustered around the midpoints. Each set of group values is centered at the midpoint for the category.
Interaction: For this option to take effect, the GROUP= option must also be specified.
GROUPORDER=DATA | ASCENDING | DESCENDING
specifies the relative position of the needle lines for clustered group display. It also sets the default order of the groups in the legend.
Default: DATA
DATA
shows each group within a category in data order of the group column.
ASCENDING
shows each group within a category in ascending order of the group column. See the Details for more information.
DESCENDING
shows each group within a category in descending order of the group column. See the Details for more information.
Interaction: This option is ignored unless GROUP= is specified.
Interaction: The SORTORDER= setting in a DISCRETELEGEND statement overrides the legend item order.
Note: Attributes such as color, symbol, and pattern are assigned to each group in the DATA order by default regardless of the GROUPORDER= option setting.
Note: The ASCENDING and DESCENDING settings linguistically sort the group values within each category (or X value) for display position purposes only. The data order of the observations and the visual attributes that are assigned to the group values remain unchanged.
Tip: The CLUSTERWIDTH= option can be used to control the distance between the group markers in a cluster
Tip: The INDEX= option can be used to alter the default sequence of visual attributes that is assigned to the needle lines.
Details: By default, the value that is set for this option determines the order in which attributes are assigned to each group. It also determines the order in which the groups are displayed in the legend.
For ASCENDING and DESCENDING sort orders, the order is based on the data type:
  • For Numeric data, the order is base on unformatted values.
  • For Character data the order is based on formatted values.
The ASCENDING and DESCENDING settings perform a linguistic sort on the group items and have the same effect as sorting the input data. However, the data is not changed.
INCLUDEMISSINGGROUP=boolean
specifies whether missing values of the group variable are included in the plot.
Default: TRUE
Interaction: For this option to take effect, the GROUP= option must also be specified.
Tip: Unless a discrete attribute map is in effect or the INDEX= option is used, the attributes of the missing group value are determined by the GraphMissing style element except when the MISSING= system option is used to specify a non-default missing character or when a user-defined format is applied to the missing group value. In those cases, the attributes of the missing group value are determined by a GraphData1–GraphDataN style element.
INDEX=numeric-column
specifies indices for mapping needle attributes (color, marker symbol, and line pattern) to one of the GraphData1–GraphDataN style elements.
Default: no default
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.
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 the legend item that is associated with this plot.
Default: The Y-variable label. If a label is not defined, the Y-variable name.
Restriction: This option applies only to an associated DISCRETELEGEND statement.
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 needle lines 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 that can be used to display information in the tooltips.
Default: no user-defined roles
(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 is a valid reference.
Requirement: To generate selectable needle lines, 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.