Example Program and Statement Details

The BARCHART statement takes raw, unsummarized data as input and calculates appropriate summarization statistics (sum, mean, and so on).

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. For non-grouped data, duplicated category values are summarized into a unique value. All values are treated as discrete. For grouped data, the category values are summarized as needed. (See the option.)

The BARCHART statement creates a bar chart with bars that represent summarized response values that are categorized by the unique category values. To create a chart that represents response values along an interval axis, use the HISTOGRAM statement.

Arguments

X= column | expression specifies the column or expression for the category values. This argument is required. Y= numeric-column | expression specifies the numeric column or expression for the response values. This argument is optional.

Options

Statement Option Description Specifies whether the bar statistic value is displayed at the end of the bar. Specifies the text properties of the bar label text. Specifies the text format used to display the bar label. 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. Enhances the visual appearance of the filled bars.

Specifies the degree of the transparency of the bar fill, bar outline, and connect line, if displayed.

Specifies an amount to offset all bars from the category midpoints. Specifies which bar features are displayed. Specifies the appearance of the filled bar area. Specifies the appearance of the pattern-filled bar area Creates a separate segment or 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 the statistic to be computed for the Y-axis. Specifies the target value for each bar. Specifies the information to display when the cursor is positioned over a bar. Specifies display formats for the information that is defined by the tooltip roles. Specifies display labels for the information that is defined by the tooltip 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. BARLABEL= boolean specifies whether the bar statistic value is displayed at the end of the bar. Default: FALSE

Tip: The font and color attributes for the label are specified by the BARLABELATTRS= option. The text format is specified by the BARLABELFORMAT= option.

BARLABELATTRS= style-element | style-element ( text-options ) | ( text-options )

specifies the text properties of the bar label text. 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, BARLABEL=TRUE must be specified. BARLABELFORMAT= format specifies the text format used to display the bar label. Default: The column format assigned to the Y= variable or BEST6. if no format is assigned. Interaction: For this option to take effect, BARLABEL=TRUE must be specified. BARWIDTH= number specifies the width of a bar as a ratio of the maximum possible width.

Default: .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. 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.

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) Note: When GROUPDISPLAY=CLUSTER, the default BARWIDTH is 1.0. 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. DATASKIN=NONE | PRESSED | SHEEN | CRISP | GLOSS | MATTE enhances the visual appearance of the filled bars. Default: NONE

Requirement: For this option to have any effect, the fill must be enabled by the ODS style or the option.

Interaction: The data skin appearance is based on the color.

Interaction: When a data skin is applied, all bar outlines are set by the skin, and the option is ignored.

DATATRANSPARENCY= number

specifies the degree of the transparency of the bar fill, bar outline, and connect line, if displayed.

Range: 0 (opaque) to 1 (entirely transparent)
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 BARCHART statement in the overlay:

layout overlay / cycleattrs=true xaxisopts=(display=(tickvalues)) yaxisopts=(label="Revenue" offsetmax=0.2); barchart x=year y=A_revenue / stat=sum name="A" legendlabel="A" barwidth=0.8 ; barchart x=year y=B_revenue / stat=sum name="B" legendlabel="B" barwidth=0.6 ; barchart x=year y=C_revenue / stat=sum name="C" legendlabel="C" barwidth=0.4 ; discretelegend "A" "B" "C" / title="Product:" location=inside halign=right valign=top; endlayout;

To place the different response values side by side, you can assign a different offset to each BARCHART 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); barchart x=year y=A_revenue / stat=sum name="A" legendlabel="A" discreteoffset=-0.3 barwidth=0.3 ; barchart x=year y=B_revenue / stat=sum name="B" legendlabel="B" discreteoffset=0 barwidth=0.3 ; barchart x=year y=C_revenue / stat=sum name="C" legendlabel="C" discreteoffset=+0.3 barwidth=0.3 ; discretelegend "A" "B" "C" / title="Product:" location=inside halign=right valign=top; endlayout;

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); barchart x=year y=A_revenue / stat=sum name="A" legendlabel="A" datatransparency=0.2 discreteoffset=-0.2 barwidth=0.5 ; barchart x=year y=B_revenue / stat=sum name="B" legendlabel="B" datatransparency=0.2 discreteoffset=0 barwidth=0.5 ; barchart x=year y=C_revenue / stat=sum 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;