Example Program and Statement Details

Example Graph 1

The following vertical high-low chart was generated by Example Program 1:
Example Vertical High-low Plot

Example Program 1

proc template;
define statgraph highlow;
  begingraph;
    layout overlay /
        yaxisopts=(griddisplay=on label="Stock Value");
      highlowplot x=date high=high low=low /
        open=open close=close;
    endlayout;
  endgraph;
end;

proc sgrender data=sashelp.stocks template=highlow;
  where date >= '01JAN03'd and stock="IBM";
run;

Example Graph 2

The following horizontal high-low chart was generated by Example Program 2:
Horizontal High-low Plot

Example Program 2

data highlowbar;
  length cap $ 12;
  input drug $ 1-10 low high cap $;
  datalines;
Drug A    10   20  NONE
Drug A    30   60  FILLEDARROW
Drug B    20   35  NONE
Drug B    50   75  FILLEDARROW
Drug C    30   90  FILLEDARROW
;
proc template;
define statgraph highlowbar;
  begingraph;
    entrytitle 'Medications Plot';
    layout overlay /
      xaxisopts=(
        griddisplay=on
        linearopts=(viewmin=0 viewmax=100)
        display=(line ticks tickvalues))
      yaxisopts=(
        griddisplay=on
        display=(line ticks tickvalues));
      highlowplot y=drug high=high low=low /
        group=drug outlineattrs=(pattern=solid)
        datatransparency=0.4
        type=bar barwidth=0.4
        highcap=cap lowcap=cap;
    endlayout;
  endgraph;
end;

proc sgrender data=highlowbar template=highlowbar;
run;

Statement Summary

A high-low chart specifies that floating vertical or horizontal lines or bars connect the minimum and maximum response values for each value of a categorical variable. The data should have at least two response values for every category value. Otherwise, the single value is displayed without the connecting line or bar. In the statement syntax, the X and Y arguments can specify a column with character or numeric values. The LOW and HIGH arguments must specify a numeric column.
The HIGHLOWPLOT statement can be used to create a graph showing the high and low response values for observations along a time axis. The independent variable can be interval or discrete. The HIGHLOWPLOT has two common uses:
  • One typical use of a high-low graph is in the financial industry to plot stock values by day. The OPEN= and CLOSE= options are typically used in the graph, and the TYPE= option is set to LINE (the default), as illustrated in Example Graph 1.
  • Another typical use of a high-low graph is in the Health and Life Sciences industry to display over time the duration of adverse events or of adverse reactions to medication. The HIGHCAP= and LOWCAP= options are typically used in the graph, and the TYPE= option is set to BAR, as illustrated in Example Graph 2.
For both vertical and horizontal high-low charts, the data values can be grouped using the GROUP= option. For grouped data, the data values are not summarized. Each observation is plotted independently, and the line or bar segment for each category value can use different display characteristics.

Arguments

Either the X= or Y= argument must be specified, but you cannot specify both on the same HIGHLOWPLOT statement. The HIGH= and LOW= arguments are required.
X=column | expression
specifies a column or expression representing the values in a vertical high-low chart. The values can be character or numeric.
Y=column | expression
specifies a column or expression representing the values in a horizontal high-low chart. The values can be character or numeric.
LOW=numeric-column | expression
specifies a column or expression representing the values of the lower end of the floating bar or line.
HIGH=numeric-column | expression
specifies a column or expression representing the values of the higher end of the floating bar or line.

Options

Statement Option
Description
Specifies the width of a bar as a ratio of the maximum possible width.
Specifies a column or expressions whose values are used to display a closing-value indicator on the bar or line.
Specifies the width of the group clusters as a fraction of the midpoint spacing.
Specifies the degree of the transparency of the colored regions and the outlines around them.
Specifies an amount to offset all bars or lines from the category midpoints when graphing multiple response variables side by side on a common axis.
Specifies whether to display outlined colored regions or just colored regions.
Specifies the policy for displaying end caps, when present.
Specifies the appearance of the interior fill area of the bars.
Creates a distinct set of floating bars or lines for each unique group value of the specified column.
Specifies whether grouped bars or lines are overlaid or clustered around the category midpoints.
Specifies the sort order for grouped bars or lines.
Specifies the type of cap to use at the high end of the bar or line.
Specifies the label to display at the high end of the bar or line.
Specifies whether missing values of the group variable are included in the plot.
Specifies indices for mapping color and line patterns to group values.
Specifies the width of the floating bars.
Specifies the color and font attributes of the labels for the bars or lines.
Specifies the attributes of the floating plot lines when the TYPE= option is set to LINE.
Specifies the type of cap used at the low end of the bar or line.
Specifies the label to appear at the low end of each floating bar or line.
Assigns a name to a plot statement for reference in other template statements.
Specifies a column or expressions whose values are used to display an opening-value indicator on the bar or line.
Specifies the appearance of the outlines of the filled regions.
Specifies that the data columns for this plot and the plot type 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 bar or line.
Specifies display formats for information defined by the tooltip roles.
Specifies display labels for information defined by the tooltip roles.
Specifies whether data values should be represented by bars or lines.
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.
BARWIDTH= number
specifies the width of a bar as a ratio of the maximum possible width.
Default: 0.85 of the tick spacing. The bar width automatically adjusts, based on the number of bars to be displayed and the wall width.
Range: 0.1 (narrowest) to 1.0 (widest)
Restriction: This option is available only when TYPE=BAR.
Tip: This option is needed only to change the default behavior. For example, to remove any inner-bar gap, set BARWIDTH=1.
Tip: See the DISCRETEOFFSET= option for examples of using this option.
CLOSE=numeric-column | expression
specifies a column or expressions whose values are used to display a closing-value indicator. This option is typically used when TYPE=LINE, but it can be used when TYPE=BAR.
Default: no default
Discussion:
  • For vertical high-low charts, the value is represented by a short horizontal line extending from the side that displays the higher X values
  • For horizontal high-low charts, the value is represented by a short vertical line extending from the side that displays the higher Y values.
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, and the GROUPDISPLAY= option must be set to CLUSTER.
DATATRANSPARENCY=number
specifies the degree of the transparency of the colored regions.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Tip: The FILLATTRS option can be used to set transparency for just the colored regions. You can combine this option with FILLATTRS= to set one transparency for the outlines but a different transparency for the region fills . Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
DISCRETEOFFSET=number
specifies an amount to offset all bars or lines from the category midpoints when graphing multiple response variables side by side on a common axis.
Default: 0 (no offset, all bars or lines are centered on the category midpoints)
Range: -0.5 to +0.5, where .5 represents half the distance between category ticks. Normally, a positive offset is to the right for a vertical plot and up for a horizontal plot. (If the layout's axis options set REVERSE=TRUE, then the offset direction is also reversed.)
Interaction: This option is available only for a discrete X or discrete Y axis.
Discussion: This feature is useful for graphing multiple response variables side by side on a common axis. By default within an overlay-type layout, if multiple HIGHLOWPLOT statements are used with different response variables, the bars or lines for matching category values are centered on the midpoints and superimposed on each other. In those cases, you can make it easier to distinguish among superimposed bars or lines by assigning a different width for them in each HIGHLOWPLOT statement in the overlay.
If you prefer to avoid superimposed bars or lines, you can assign a different offset to each HIGHLOWPLOT statement. If desired, you can adjust the width of the bar or line in conjunction with DISCRETEOFFSET= to create narrower bars that require less width within the plot area.
The following example defines offsets for the lines in a stock report:
layout overlay / cycleattrs=true
    yaxisopts=(label="Stock Value");
  highlowplot x=month high=a_high low=a_low /
    close=a_close open=a_open
    legendlabel="A" name="ahighlow" lineattrs=(pattern=solid)
    discreteoffset=-0.2 ;
  highlowplot x=month high=b_high low=b_low /
    close=b_close open=b_open
    legendlabel="B" name="bhighlow" lineattrs=(pattern=solid)
    discreteoffset=0 ;
  highlowplot x=month high=c_high low=c_low /
    close=c_close open=c_open
    legendlabel="C" name="chighlow" lineattrs=(pattern=solid)
    discreteoffset=+0.2 ;
  discretelegend "ahighlow" "bhighlow" "chighlow" / title="Stock"
    location=inside halign=right valign=top;
endlayout;
High-low Plot with Midpoint Offsets
DISPLAY=STANDARD | ALL | (display-options)
specifies whether to display outlined colored regions or just colored regions.
Default: STANDARD
STANDARD
displays outlined, colored regions
ALL
displays outlined, colored regions
(display-options)
a list of options, enclosed in parentheses, that must include at least one of the following:
FILL displays filled (colored) regions
OUTLINE displays outlined regions
Interaction: For this option to take effect, TYPE=BAR must also be specified.
ENDCAPDISPLAYPOLICY= AUTO | ALWAYS
specifies the policy for displaying end caps, when present.
Note: This feature is for the second maintenance release of SAS 9.3 and later. See What's New in the SAS 9.3 Graph Template Language.
AUTO
only draw the end caps for the elements with a low to high range that is large enough to accommodate the end caps. Draw just the bar or line for the rest.
ALWAYS
always draw the end caps.
Note: When the low to high range is not large enough for the end caps, the end caps might overlap. The data ranges that are smaller than the end-cap size might not be resolvable beyond the rendered size of the end caps.
Default: AUTO
Interaction: This option is honored only when the TYPE=LINE option is in effect. See TYPE=.
Interaction: This option is ignored if the LOWCAP= or HIGHCAP= option is not set or is effectively set to NONE. See LOWCAP= and HIGHCAP=.
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the appearance of the interior fill area of the bars. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
Default:
  • For non-grouped data, the GraphDataDefault:Color style reference.
  • For grouped data, the Color attribute of GraphData1–GraphDataN style elements.
Interaction: For this option to take effect, TYPE=BAR must also be specified.
Tip: The DATATRANSPARENCY= option sets the transparency for the colored regions and the outlines around them. You can combine this option with DATATRANSPARENCY= to set one transparency for the outlines but a different transparency for the colored regions. Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
GROUP=column | discrete-attr-var | expression
creates a distinct set of floating bars or lines 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:
  • If fills are enabled by the ODS style or the DISPLAY= option, each distinct group value is represented in the graph by a different fill color. The fill colors are defined by the GraphData1:Color–GraphDataN:Color style references.
  • For floating lines when TYPE=LINE. and for outlines when TYPE=BAR (if outlines are enabled by the ODS style or the DISPLAY= option), each distinct group value is represented in the graph by a different line color and line pattern. The colors and patterns are defined by the ContrastColor and LineStyle attributes of the GraphData1–GraphDataN style elements.
Interaction: If the X or Y role is discrete, then the bars or lines representing the group can be drawn in a cluster or overlaid, based on the setting for the GROUPDISPLAY= option. However, if the X or Y role is interval, then the lines representing the group are overlaid and the GROUPDISPLAY= option is ignored.
Interaction: By default, the group values are mapped in the order of the data. The GROUPORDER= option can be used to control the sorting order of the grouped bar segments. The INDEX= option can be used to alter the default sequence of colors and line patterns.
Interaction: The INCLUDEMISSINGGROUP= option determines 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, if each distinct group value is represented by a different line pattern, the LINEATTRS= (PATTERN=pattern) specification can be used to assign the same line pattern to all the plot lines. In that case, the line color denotes group values. Likewise, LINEATTRS= (COLOR= color) can be used to assign the same color to all lines, letting line pattern denote group values.
GROUPDISPLAY= OVERLAY | CLUSTER
specifies whether grouped bars or lines are overlaid or clustered around the category midpoints.
Default: OVERLAY
OVERLAY
bars or lines for matching category values are centered on the midpoints and superimposed on each other.
CLUSTER
bars or 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.
The following example shows the effect of clustering the lines in a stock report when the category values are grouped into a single response variable. Note that if your category values are not grouped in the same variable but are stored in separate variables, you can get this same effect by using the DISCRETEOFFSET= option.
layout overlay / 
    yaxisopts=(label="Stock Value");
  highlowplot x=month high=high low=low /
    close=close open=open
    legendlabel="Stock" name="cluster"
    group=stock groupdisplay=cluster
    lineattrs=(pattern=solid);
  discretelegend "cluster" / title="Stock"
    location=inside halign=right valign=top;
endlayout;
Clustered Category Values
GROUPORDER=DATA | ASCENDING | DESCENDING
specifies the sort order for grouped bars or lines. It also sets the default order of the groups in the legend.
Default: DATA
DATA
shows each group of bars in data order of the group column.
ASCENDING
shows each group of bars in ascending order.
DESCENDING
shows each group of bars in descending order.
Interaction: For this option to take effect, the GROUP= option must also be specified.
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.
HIGHCAP = column | NONE | SERIF | BARBEDARROW | FILLEDARROW | OPENARROW | CLOSEDARROW
specifies the type of cap used at the high end of the bar or line. This option is typically used when TYPE=BAR, but it can be used when TYPE=LINE.
Default: NONE
Interaction: All of the keywords can be specified for any high-low chart, but the effect of each keyword depends on the setting for the TYPE= option and also the fill state of the bars, when displayed:
  • TYPE=BAR: If the bars are filled, FILLEDARROW is used for all settings other than NONE. If the bars are not filled, CLOSEDARROW is used.
  • TYPE=LINE: If CLOSEDARROW is specified, it is treated as FILLEDARROW.
HIGHLABEL= column | expression
specifies the label to display at the high end of the bar or line.
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 | expression
specifies indices for mapping color and line patterns to group values.
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 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: The index values are 1-based indices. For the style definitions 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 to use.
Interaction: If this option is not used, then the group values are mapped according to the setting of the GROUPORDER= option.
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.
INTERVALBARWIDTH= dimension
specifies the width of the floating bars.
Default: 85% of the smallest interval between any two bars for the given plot
Restriction: For this option to take effect, TYPE=BAR must be set, and the independent variable must be of type interval.
LABELATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the labels for the bars or lines. 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 data label color changes to match the group color derived from the ContrastColor attribute of the GraphData1–GraphDataN style elements.
LINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the floating plot lines. 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.
Interaction: For this option to have any effect, TYPE=LINE must also be specified.
LOWCAP = column | NONE | SERIF | BARBEDARROW | FILLEDARROW | OPENARROW | CLOSEDARROW
specifies the type of cap used at the low end of the bar or line. This option is typically used when TYPE=BAR, but it can be used when TYPE=LINE.
Default: NONE
Interaction: All of the keywords can be specified for any high-low chart, but the effect of each keyword depends on the setting for the TYPE= option and also the fill state of the bars, when displayed:
  • TYPE=BAR: If the bars are filled, FILLEDARROW is used for all settings other than NONE. If the bars are not filled, CLOSEDARROW is used.
  • TYPE=LINE: If CLOSEDARROW is specified, it is treated as FILLEDARROW.
LOWLABEL=column | expression
specifies the label to appear at the low end of each floating bar or line.
Default: no default
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.
OPEN=numeric-column | expression
specifies a column or expressions whose values are used to display an opening-value indicator. This option is typically used when TYPE=LINE, but it can be used when TYPE=BAR.
Default: no default
Discussion:
  • For vertical high-low charts, the value is represented by a short horizontal line extending from the side that displays the lower X values
  • For horizontal high-low charts, the value is represented by a short vertical line extending from the side that displays the lower Y values.
OUTLINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the appearance of the outlines of the filled regions. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The ContrastColor and LineThickness attributes of the GraphOutlines style element.
Interaction: For this option to have any effect, outlines must be enabled by the ODS style or the DISPLAY= option.
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.
ROLENAME= (role-name-list)
specifies user-defined roles that can be used to display information in the tooltips. Columns for the tooltip display are specified in the TIP= option.
Default: no user-defined roles
(rolename-list)
a blank-separated list of rolename = column pairs.
For example, ROLENAME=(TIP1=PCT) assigns the data column PCT to the user-defined role TIP1.
Requirement: The role names that you choose must be unique and different from the pre-defined roles X and Y.
Interaction: For this option to take effect, the TIP= option must also be used.
TIP=(role-list)
specifies the information to display when the cursor is positioned over a bar or line. If this option is used, it replaces all the information displayed by default. Roles for columns that do not contribute to the bar chart can be specified along with roles that do.
Default: The columns assigned to these roles are automatically included in the tooltip information: X and Y.
(role-list)
an ordered, blank-separated list of unique HIGHLOWPLOT and user-defined roles. HIGHLOWPLOT roles include X, Y, LOW, HIGH, OPEN, and CLOSE.
The following example displays tooltips for the columns X and PCT. The PCT column is not assigned to any pre-defined HIGHLOWPLOT role, so it must first be assigned a role:
ROLENAME=(TIP1=PCT)
TIP=(X TIP1)
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 information defined by the tooltip roles.
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 role-name = format pairs separated by blanks.
ROLENAME=(TIP1=PCT)
TIP=(TIP1 X)
TIPFORMAT=(TIP1=PERCENT7.2)
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.
TIPLABEL=(role-label-list)
specifies display labels for information defined by the tooltip roles.
Default: The column label or column name of the variable assigned to the role.
(role-label-list)
a list of role-name = "string" pairs separated by blanks.
ROLENAME=(TIP1=PCT)
TIP=(TIP1 X)
TIPLABEL=(TIP1="Percent")
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.
TYPE= LINE | BAR
specifies whether data values should be represented by bars or lines.
Default: LINE
BAR
uses fill and outline attributes.
LINE
uses line attributes.
XAXIS=X | X2
specifies whether data are mapped to the primary X (bottom) axis or to the secondary X2 (top) axis.
Default: X
Interaction: When the Y= argument is specified, the HIGH= and LOW= arguments are mapped to the axis that is specified on this option (X or X2).
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: When the X= argument is specified, the HIGH= and LOW= arguments are mapped to the axis that is specified on this option (Y or Y2).
Interaction: The overall plot specification and the layout type determine the axis display. For more information, see How Axis Features Are Determined.