Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Bar Chart

Example Program

proc template;
  define statgraph barchartparm;
    begingraph;
      entrytitle "Average Mileage by Vehicle Type";
      entryfootnote halign=left
        "Error bars show +/- 1 Standard Error";
      layout overlay;
        barchartparm x=type y=mean / 
          errorlower=eval(mean-stderr)
          errorupper=eval(mean+stderr) ;
      endlayout;
    endgraph;
  end;
run;

/* create summarized data for barchartparm */
proc summary data=sashelp.cars nway;
  class type;
  var mpg_highway;
  output out=mileage mean=mean stderr=stderr ;
run;

proc sgrender data=mileage template=barchartparm;
run;

Statement Summary

The input data for the BARCHARTPARM statement is expected to be pre-summarized, with appropriate summarization statistics (sum, mean, and so on) computed for the Y column. When the X values are not unique, the display is not meaningful.
By default, if the category column is character, the bars in the chart appear in the order in which the category values are present in the input data. If the category column is numeric, the values are presented in ascending order.

Required Arguments

X=column | expression
specifies the column for the unique category values. All values are treated as discrete.
Y=numeric-column | expression
specifies the column for the response values.

Options

Statement Option
Description
Specifies the bar width as a ratio of the maximum width.
Specifies the response axis intercept for the baseline.
Specifies the width of the group clusters as a fraction of the midpoint spacing.
Specifies the properties of the line connecting bars.
Specifies the label to appear at the end of each bar.
Specifies the color and font attributes of the labels that are specified in the DATALABEL= option.
Enhances the visual appearance of the filled bars.
Specifies the degree of the transparency of the bar fill, bar outline, error bars, and connect line, if displayed.
Specifies an amount to offset all bars from the category midpoints.
Specifies which bar features are displayed.
Specifies the attributes of the error bars.
Specifies the values of the lower endpoints on the error bars.
Specifies the values of the upper endpoints on the error bars.
Specifies the appearance of the filled bar area.
Specifies the appearance of the pattern-filled bar area.
Creates a separate segment within each bar for each unique group value of the specified column.
Specifies how to display grouped bars.
Specifies the order of the grouped bars for each category value.
Specifies whether missing values of the group variable are included in the plot.
Specifies indices for mapping line attributes (color and pattern) to one of the GraphData1–GranphDataN style elements.
Specifies the label for the legends.
Assigns a name to a plot statement for reference in other template statements.
Specifies the orientation of the Y axis and the bars.
Specifies the properties of the bar outlines.
Specifies that the data columns for this chart and the chart type be used for determining default axis features.
Specifies user-defined roles that can be used to display information in the tooltips.
Specifies the target value for each bar.
Specifies the information to display when the cursor is positioned over a bar.
Specifies display formats for information defined by roles.
Specifies display labels for information defined by roles.
Specifies an HTML page to display when a bar 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.
BARWIDTH=number
specifies the width of a bar as a ratio of the maximum possible width.
Default: 0.85. By default, the bar width automatically adjusts based on the number of bars to be displayed and the wall width.
Range: 0 .1 (narrowest) to 1 (widest)
This option is needed only to change the default behavior. For example, to remove any inter-bar gap, set BARWIDTH=1.
BASELINEINTERCEPT=number
specifies the response axis intercept for the baseline.
Default: 0
Interaction: Label positions are adjusted to prevent the labels from overlapping.
Interaction: If GROUPDISPLAY=STACKED is specified, this option is ignored and the baseline is not displayed.
Tip: The baseline does not add a tick or a tick value to the axis. To label the baseline, you can use a REFERENCELINE statement to overlay a line with the same X or Y value and use the REFERENCELINE statement’s CURVELABEL= option.
Details: When this option is used, the axis range is adjusted to include the baseline, and the baseline is placed at the specified value on the response axis.
Graph with BASLINEINTERCEPT=0
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.
Note: When GROUPDISPLAY=CLUSTER, the default BARWIDTH is 1.0.
Clusters in a Bar Chart
CONNECTATTRS=style-element | style-element (line-options) | (line-options)
specifies the appearance of the bar connect lines. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphConnectLine style element.
DATALABEL= column | expression
specifies the label to appear at the end of each bar.
Default: no bar labels are displayed
Interaction: If the GROUP= option is used and there are multiple input observations per bar for the GROUP= column, the value for the DATALABEL= column should be the same for each observation that is on the same bar.
DATALABELATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the labels that are specified in the DATALABEL= option. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphDataText style element.
Interaction: For this option to take effect, the DATALABEL= option must also be used.
DATASKIN=NONE | PRESSED | SHEEN | CRISP | GLOSS | MATTE
enhances the visual appearance of the filled bars.
Bar Chart with Data Skins
Default: NONE
Requirement: For this option to have any effect, the fill must be enabled by the ODS style or the DISPLAY= option.
Interaction: The data skin appearance is based on the FILLATTRS= color.
Interaction: When a data skin is applied, all bar outlines are set by the skin, and the OUTLINEATTRS= option is ignored.
DATATRANSPARENCY=number
specifies the degree of the transparency of the bar fill, bar outline, error bars, and connect line, if displayed.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Tip: The FILLATTRS= option can be used to set transparency for just the bar fills. You can combine this option with FILLATTRS= to set one transparency for the bar outlines, error bars, and connect lines but a different transparency for the bar fills. Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
DISCRETEOFFSET=number
specifies an amount to offset all bars from the category midpoints.
Default: 0 (no offset, all bars 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 when ORIENT=VERTICAL, and up when ORIENT=HORIZONTAL. (If the layout's axis options set REVERSE=TRUE, then 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 multiple BARCHART statements are used with different response variables, the bars for matching category values are centered on the midpoints and the bars are superimposed. To make it easier to distinguish among superimposed bars, you can assign a different BARWIDTH= setting to each BARCHARTPARM statement in the overlay:
layout overlay / cycleattrs=true
    xaxisopts=(display=(tickvalues))
    yaxisopts=(label="Revenue" offsetmax=0.2);

  barchartparm x=year y=A_revenue / name="A"
    legendlabel="A" barwidth=0.8 ;
  barchartparm x=year y=B_revenue / name="B"
    legendlabel="B" barwidth=0.6 ;
  barchartparm x=year y=C_revenue / name="C"
    legendlabel="C" barwidth=0.4 ;

  discretelegend "A" "B" "C" / title="Product:"
    location=inside halign=right valign=top;
endlayout;
Bar Chart with Bars Centered on Midpoints
To place the different response values side by side, you can assign a different offset to each BARCHARTPARM statement. If desired, the BARWIDTH= option can be used in conjunction with DISCRETEOFFSET= to create narrower bars that require less width within the plot area:
layout overlay / cycleattrs=true
    xaxisopts=(display=(tickvalues))
    yaxisopts=(label="Revenue" offsetmax=0.2);

  barchartparm x=year y=A_revenue / name="A"
    legendlabel="A"
    discreteoffset=-0.3 barwidth=0.3 ;
  barchartparm x=year y=B_revenue / name="B"
    legendlabel="B"
    discreteoffset=0    barwidth=0.3 ;
  barchartparm x=year y=C_revenue / name="C"
    legendlabel="C"
    discreteoffset=+0.3 barwidth=0.3 ;

  discretelegend "A" "B" "C" / title="Product:"
    location=inside halign=right valign=top;
endlayout;
Bar Chart with Midpoint Offsets
Different combinations of DISCRETEOFFSET and BARWIDTH can be used to get the effect that you want. Gaps can be created between bars by providing a narrower bar width. Or, bars can be overlapped if the bar widths are increased in proportion to the discrete offset.
layout overlay / cycleattrs=true 
    xaxisopts=(display=(tickvalues))
    yaxisopts=(label="Revenue" offsetmax=0.2);

  barchartparm x=year y=A_revenue / name="A"
    legendlabel="A" datatransparency=0.2
    discreteoffset=-0.2 barwidth=0.5 ;
  barchartparm x=year y=B_revenue / name="B"
    legendlabel="B" datatransparency=0.2
    discreteoffset=0   barwidth=0.5 ;
  barchartparm x=year y=C_revenue / name="C"
    legendlabel="C" datatransparency=0.2
    discreteoffset=+0.2 barwidth=0.5 ;

  discretelegend "A" "B" "C" / title="Product:"
    location=inside halign=right valign=top;
endlayout;
Bar Chart with Overlapping Bars
DISPLAY=STANDARD | ALL | (display-options)
specifies which bar features to display.
Default: STANDARD
STANDARD
displays outlined, filled bars
ALL
displays outlined, filled bars and also connect lines
(display-options)
a list of options, enclosed in parentheses, that must include one of the following:
OUTLINE Displays outlined bars.
FILL Displays bars with a solid fill.
CONNECT Displays line segments connecting adjacent midpoints at the end of each bar.
FILLPATTERN Displays bars with a patterned fill. This setting is used primarily for grouped bar charts that must be rendered in monochrome for use in a journal article. The fill patterns make it easier to distinguish among groups when color is not available.
Interaction: Connect lines are not drawn for grouped data.
Error bars are automatically displayed whenever the ERRORUPPER= or ERRORLOWER= options are specified.
Use the OUTLINEATTRS=, FILLATTRS=, and FILLPATTERNATTRS= options to control the appearance of the bars. Use CONNECTATTRS= to control the appearance of the connect lines.
Tip: Both FILL and FILLPATTERN can be specified to combine solid fills and pattern fills in the bars.
ERRORBARATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the error bars associated with the bars. 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.
ERRORLOWER=numeric-column | expression
specifies the values of the lower endpoints on the Y error bars.
Default: The lower segment of the error bars is not drawn.
Interaction: If the GROUP= option is specified and GROUPDISPLAY=STACK, this option is ignored.
The error bar values must be absolute data values, not data values relative to the value of the bar.
The appearance of the error bars is controlled by the ERRORBARATTRS= option.
ERRORUPPER=numeric-column | expression
specifies the values of the upper endpoints on the Y error bars.
Default: The upper segment of the error bars is not drawn.
Interaction: If the GROUP= option is specified and GROUPDISPLAY=STACK, this option is ignored.
The error bar values must be absolute data values, not data values relative to the value of the bar.
The appearance of the error bars is controlled by the ERRORBARATTRS= option.
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the appearance of the filled bar area. 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 GraphData1:Color–GraphDataN:Color style references.
Tip: The DATATRANSPARENCY= option sets the transparency for bar fills, bar outlines, error bars, and connect lines. You can combine this option with DATATRANSPARENCY= to set one transparency for the bar outlines, error bars, and connect lines but a different transparency for the bar fills. Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
FILLPATTERNATTRS=style-element | style-element (fill-options) | (fill-pattern-options)
specifies the appearance of the pattern-filled bar area.
Default: no default
To specify a style-element, only one of the elements GraphData1–GraphDataN can be used, subject to the Restriction listed in a moment.
The following fill-pattern-options are available:
COLOR = color | style-reference
specifies a color to use for the bar-fill-pattern lines. With grouped data, this setting has the effect of holding the pattern line color constant across all group values.
PATTERN = line-pattern
specifies a line pattern to use for the bar fill.
To specify a line-pattern, combine a line-direction prefix (R for right, L for left, and X for cross hatch) with a line-identification number:
Bar Chart Fill Patterns
With grouped data, this PATTERN= setting has the effect of holding the fill pattern constant across all group values.
Restriction: The only SAS-delivered styles that support fill patterns are JOURNAL2, JOURNAL3, and MONOCHROMEPRINTER. If any other SAS-delivered style is in effect and this option uses a style-element in its specification, this option is ignored.
Interaction: For this option to take effect, the DISPLAY= option must include FILLPATTERN among the display options.
GROUP=column | discrete-attr-var | expression
creates a separate bar segment or bar 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 bar 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 or fill pattern. The fill colors are defined by the GraphData1:Color–GraphDataN:Color style references. The fill patterns are defined by the GraphData1:FillPattern–GraphDataN:FillPattern style references.
  • If bar outlines are enabled by the ODS style or the DISPLAY= option, each distinct group value is represented in the graph by a different outline. The outline colors are defined by the GraphData1:ContrastColor–GraphDataN:ContrastColor style references.
Interaction: The bar display depends on the setting for the GROUPDISPLAY= option. For example, for a vertical bar chart with GROUPDISPLAY=STACK, the bar segments are stacked to form the bar. The height of each segment represents the corresponding group value’s proportional contribution to the response value.
Interaction: Connect lines are not drawn for grouped data.
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 group values. The INDEX= option can be used to alter the default sequence of colors, fill patterns, and line patterns.
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 individually. For example, each distinct group value is represented by a different line pattern for the bar outlines, but the PATTERN= setting in the OUTLINEATTRS= option could be used to assign the same line pattern to all bar outlines and connect lines.
GROUPDISPLAY=STACK | CLUSTER
specifies how to display grouped bars.
Default: STACK
STACK
Displays group values as stacked segments within the category bar.
Bar Chart with Stacked Bars
CLUSTER
Displays group values as separate adjacent bars that replace the single category bar. Each set of group values is centered at the category midpoint on the axis. This example illustrates the clusters and also how groups are displayed when they have an unequal number of unique values.
Bar Chart with Clustered Bars
GROUPORDER=DATA | ASCENDING | DESCENDING
specifies the order of the grouped bars for each category value. It also sets the default order of the groups in the legend.
Default: DATA
DATA
shows each group of bars for each category 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: This option is ignored unless GROUP= is 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.
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 line attributes (color and pattern) to one of the GraphData1–GranphDataN 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 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 in the order of the data.
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.
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.
ORIENT= VERTICAL | HORIZONTAL
specifies the orientation of the Y axis and the bars.
Default: VERTICAL
Tip: When this option is set to VERTICAL, the category variable appears on the X (or X2) axis and the response variable appears on the Y (or Y2) axis. To set the axis properties for this chart, you should use the appropriate axis options of the layout container.
When this option is set to HORIZONTAL, the category variable appears on the Y (or Y2) axis and the response variable appears on the X (or X2) axis. To set the axis properties for this chart, you should use the appropriate axis options of the layout container.
Tip: If you change the orientation of the bar chart, you should adjust the layout container’s axis options appropriately.
OUTLINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the appearance of the bar outlines. 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 ContrastColor and LineThickness attributes of the GraphOutlines style element.
  • For grouped data, the ContrastColor and LineThickness attribute of the GraphData1–GraphDataN style elements.
Interaction: For this option to have any effect, outlines must be enabled by the ODS style or the DISPLAY= option.
Interaction: If the DATASKIN= option applies a data skin, this option is ignored.
PRIMARY=boolean
specifies that the data columns for this chart 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 role-name = column pairs.
For example, ROLENAME= (TIP1=PCT) assigns the 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, Y, ERRORLOWER, ERRORUPPER, GROUP, and INDEX.
This option provides a way to add to the data columns that appear in tooltips specified by the TIP= option.
TARGET=numeric-column | expression
specifies the target value for each bar. The visual representation is a triangle with a line at the target value.
layout overlay;
  barchartparmm x=type y=mpg_highway / barwidth=.8
    target=mpg_city group=origin groupdisplay=cluster
    name='bar';
  discretelegend 'bar';
endlayout;
Bar Chart with Target Markers
Default:No targets are displayed.
Interaction: For this option to take effect, the Y= argument must also be used.
Interaction: If the GROUP= option is used and GROUPDISPLAY=STACK, this option is ignored.
Tip: The target color is that of the bar outline.
TIP=(role-list)
specifies the information to display when the cursor is positioned over a bar. 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, Y, ERRORLOWER, ERRORUPPER, and GROUP.
(role-list)
an ordered, blank-separated list of unique BARCHARTPARM and user-defined roles. BARCHARTPARM roles include X, Y, ERRORUPPER, ERRORLOWER, INDEX, 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 PCT. The PCT column is not assigned to any pre-defined bar chart role, so it must first be assigned a role.
  ROLENAME=(TIP1=PCT)
  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 role-name = format pairs separated by blanks.
  ROLENAME=(TIP1=PCT)
  TIP=(TIP1 X Y)
  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. 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 role-name = "string" pairs separated by blanks.
   ROLENAME=(TIP1=PCT) 
   TIP=(TIP1 X Y)
   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. See the ROLENAME= option.
URL=character-column
specifies an HTML page to display when the bar is selected.
Default: no default
character-column
each value of the column should be a valid HTML page reference (HREF). Example: http://www.sas.com/technologies/analytics/index.html.
Requirement: To generate selectable bars, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
For non-grouped data, the values of the column are expected to be same for each unique X value. If they are not, only the first URL value for a given X value is used. The URL value can be blank for some X values, meaning that no action is taken when the bars for those X values are selected. The URL value can be the same for different X values, meaning that the same action is taken when the bars for those X values are selected.
For grouped data, the values of the column are expected to be the same for each unique X and GROUP combination.
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.