Chapter Contents |
Previous |
Next |
The GCHART Procedure |
Requirements: | At least one chart variable is required. |
Global statements: | AXIS, LEGEND, PATTERN, TITLE, FOOTNOTE |
Supports: | Drill-down functionality |
You can use statement options to select or order the midpoints (bars), to control the tick marks on the response axis, to change the type of chart statistic, to display specific statistics, and to modify the appearance of the chart. You can also specify additional variables by which to group, subgroup, or sum the data.
All bar charts allow grouping, which uses an additional category to organize the bars into groups, and subgrouping, which divides the bars into segments.
In addition, you can use global statements to modify
the axes (including requesting a logarithmic axis), the bar patterns, and
the legend, as well as add titles, footnotes, and notes to the chart. You
can also use an Annotate data set to enhance the chart.
HBAR | HBAR3D | VBAR | VBAR3D chart-variable(s) </ option(s); > |
option(s) can be one or more options from any or all of the following categories:
ANNOTATE=Annotate-data-set | |
CAXIS=axis-color | |
CERROR=error-bar-color | |
CFRAME=background-color | |
COUTLINE=bar-outline-color | SAME | |
CTEXT=text-color | |
FRAME | NOFRAME | |
GSPACE=group-spacing | |
LEGEND=LEGEND<1...99> | |
NOLEGEND | |
PATTERNID=BY | GROUP | MIDPOINT | SUBGROUP | |
SHAPE=3D-bar-shape (HBAR3D and VBAR3D only) | |
SPACE=bar-spacing | |
WIDTH=bar-width | |
WOUTLINE=bar-outline-width |
CFREQ | |
CFREQLABEL='column-label' (HBAR and HBAR3D only) | |
CLM=confidence-level | |
CPERCENT | |
CPERCENTLABEL='column-label' (HBAR and HBAR3D only) | |
ERRORBAR=BARS | BOTH | TOP | |
FREQ | |
FREQLABEL='column-label' (HBAR and HBAR3D only) | |
FREQ=numeric-variable | |
G100 | |
INSIDE=statistic (VBAR and VBAR3D only) | |
MEAN | |
MEANLABEL='column-label' (HBAR and HBAR3D only) | |
NOSTATS (HBAR and HBAR3D only) | |
OUTSIDE=statistic (VBAR and VBAR3D only) | |
PERCENT | |
PERCENTLABEL='column-label' (HBAR and HBAR3D only) | |
SUM | |
SUMLABEL='column-label' (HBAR and HBAR3D only) | |
SUMVAR=summary-variable | |
TYPE=statistic |
DISCRETE | |
GROUP=group-variable | |
LEVELS=number-of-midpoints | |
MIDPOINTS=value-list | |
MIDPOINTS=OLD | |
MISSING | |
SUBGROUP=subgroup-variable |
ASCENDING | |
AUTOREF | |
AXIS=AXIS<1...99> | |
CLIPREF | |
DESCENDING | |
FRONTREF | |
GAXIS=AXIS<1...99> | |
MAXIS=AXIS<1...99> | |
MINOR=number-of-minor-ticks | |
NOAXIS | |
NOBASEREF | |
NOZERO | |
RAXIS=value-list | AXIS<1...99> | |
REF=value-list |
catalog entry description options
DESCRIPTION='entry-description' | |
NAME='entry-name' |
HTML=variable | |
HTML_LEGEND=variable |
Required Arguments |
See also: | About Chart Variables |
Options |
Options in an HBAR, HBAR3D, VBAR, or VBAR3D statement affect all graphs that are produced by that statement. You can specify as many options as you want and list them in any order. For details on specifying colors, see SAS/GRAPH Colors. For a complete description of the graphics options, see Graphics Options and Device Parameters Dictionary.
See also: | The Annotate Data Set |
If you also use the GROUP= option, the reordering is performed separately for each group, so the order of the midpoints may be different for each group.
ASCENDING overrides any midpoint order specified with the MIDPOINTS= option or specified in the ORDER= option in an AXIS statement assigned to the midpoint axis.
By default, reference lines in 2D bar charts are drawn in front of the bars. To draw reference lines behind the bars, use the CLIPREF option.
By default, reference lines in 3D bar charts are drawn on the back plane of the axis. To draw reference lines in front of the bars, use the FRONTREF option.
Featured in: | Controlling Midpoints and Statistics in a Horizontal Bar Chart |
The axis area color does not affect the frame color, which is always the same as the midpoint axis line color and controlled by the CAXIS= option. By default, the axis area in 2D bar charts is not filled.
CFRAME= is overridden by the NOFRAME option.
Note: If the background
color, the bar color, and the outline
color are the same, you may not be able to distinguish the bars.
Featured in: | Subgrouping a 3D Vertical Bar Chart |
Featured in: | Controlling Midpoints and Statistics in a Horizontal Bar Chart |
Featured in: | Generating Error Bars in a Horizontal Bar Chart |
The default outline color depends on the PATTERN statement:
Note: For 2D bar charts, if you specify
empty patterns, (VALUE=EMPTY in a PATTERN statement) you should not change
the outline color from the default value, SAME, to a single color. Otherwise
all the outlines will be one color and you will not be able to distinguish
between the empty areas.
COUTLINE= is not valid when SHAPE=CYLINDER.
CTEXT= overrides the color specification for the axis label and the tick mark values in the COLOR= option in an AXIS definition assigned to an axis.
CTEXT= is overridden by
DESCENDING overrides any midpoint order that is specified with the MIDPOINTS= option or that is specified in the ORDER= option in an AXIS statement assigned to the midpoint axis.
The entry-description can include the #BYLINE, #BYVAL, and #BYVAR substitution options, which work as they do when used on TITLE, FOOTNOTE, and NOTE statements. For more information, refer to the description of the options, and Substituting BY Line Values in a Text String. The 40-character limit applies before the substitution takes place for these options; thus, if in the SAS program the entry-description text exceeds 40 characters, it is truncated to 40 characters, and then the substitution is performed.
The descriptive text is shown in the "description" portion of each of the following:
Featured in: | Creating Bar Charts with Drill-down for the Web |
The LEVELS= option is ignored when you use DISCRETE. The MIDPOINTS= option overrides DISCRETE. The ORDER= option in an AXIS statement that is assigned to the midpoint axis can rearrange or exclude discrete midpoint values.
Featured in: | Creating Bar Charts with Drill-down for the Web |
Valid values for ERRORBAR= are:
By default, ERRORBAR= uses a confidence level of 95 percent. You can specify different confidence levels with the CLM= option.
When you use ERRORBAR= with TYPE=PCT, the confidence interval is based on a normal approximation. Let TOTAL be the total number of observations, and PCT be the percentage assigned to a given midpoint. The standard error of the percentage is approximated as
APSTDERR=100 * SQRT((PCT/100) * (1-(PCT/100)) / TOTAL);
Let LEVEL be the confidence level specified using the CLM= option, with a default value of 95. The upper confidence limit for the percentage is computed as
UCLP = PCT + APSTDERR * PROBIT( 1-(1-LEVEL/100)/2 );
The lower confidence limit for the percentage is computed as
LCLP = PCT - APSTDERR * PROBIT( 1-(1-LEVEL/100)/2 );
When you use ERRORBAR= with TYPE=MEAN, the sum variable must have at least two non-missing values for each midpoint. If the GROUP= option is used, each midpoint within a group must also have two non-missing values. Let N be the number of observations assigned to a midpoint, MEAN be the mean of those observations, and STD be the standard deviation of the observations. The standard error of the mean is computed as
STDERR = STD / SQRT(N);
Let LEVEL be the confidence level specified using the CLM= option, with a default value of 95. The upper confidence limit for the mean is computed as
UCLM = MEAN + STDERR * TINV( 1-(1-LEVEL/100)/2, N-1);The lower confidence limit for the mean is computed as
LCLM = MEAN - STDERR * TINV( 1-(1-LEVEL/100)/2, N-1);
If you want the error bars to represent a given number C of standard errors instead of a confidence interval, and if the number of observations assigned to each midpoint is the same, then you can find the appropriate value for the CLM= option by running a DATA step. For example, if you want error bars that represent one standard error (C=1) with a sample size of N , you can run the following DATA step to compute the appropriate value for the CLM= option and assign that value to a macro variable &LEVEL:
data null; c = 1; n = 10; level = 100 * (1 - 2 * (1 - probt( c, n-1))); put all; call symput('level',put(level,best12.)); run;Then when you run the GCHART procedure, you can specify CLM=&LEVEL.
Note that this trick does not work precisely if different midpoints have different numbers of observations. However, choosing an average value for N may yield sufficiently accurate results for graphical purposes if the sample sizes are large or do not vary much.
Featured in: | Generating Error Bars in a Horizontal Bar Chart |
The color of the frame or of the backplane outline is the color of the midpoint axis, which is determined by the CAXIS= option. To fill the 2D axis area with a background color, or to specify a color for the 3D backplane, use the CFRAME= option.
With 2D bar charts, NOFRAME removes the axis frame. It overrides CFRAME= and also removes the colored fill it specifies.
With 3D bar charts, NOFRAME removes the colored backplane, leaving the vertical and horizontal axis planes and axes. To remove these planes, use the NOPLANE option in the AXIS statement. To remove one or more axis elements, use either the AXIS statement or the NOAXIS option.
If the V6COMP graphics option is in effect, the default is NOFRAME.
Featured in: | Creating Bar Charts with Drill-down for the Web and Generating Error Bars in a Horizontal Bar Chart |
Featured in: | Controlling Midpoints and Statistics in a Horizontal Bar Chart |
Featured in: | Controlling Midpoints and Statistics in a Horizontal Bar Chart and Generating Error Bars in a Horizontal Bar Chart |
Because you cannot use TYPE=PERCENT, TYPE=CPERCENT, TYPE=FREQ, or TYPE=CFREQ with the SUMVAR= option, you must use FREQ= to calculate percentages, cumulative percentages, frequencies, or cumulative frequencies based on a sum.
See also: | Calculating Weighted Statistics |
By default, the individual percentages reflect the contribution of the midpoint to the entire chart and total 100 percent for the entire chart.
The AXIS statement options MAJOR= and MINOR= are ignored in AXIS definitions assigned to the group axis because the axis does not use tick marks. A warning message is written to the SAS log if these options appear in the AXIS definition.
To remove groups from the chart, use the ORDER= option in the AXIS statement.
To suppress the brackets drawn around the values on the group axis in vertical bar charts, use the NOBRACKETS option in the AXIS statement.
See also: | AXIS Statement |
Featured in: | Creating Bar Charts with Drill-down for the Web |
GROUP= produces a separate group of bars for each unique value of the group variable. Missing values for group-variable are treated as a valid group. The groups are arranged in ascending order of the group variable values.
By default, each group includes all midpoints, even if no observations for the group fall within the midpoint range, meaning that no bar is drawn at the midpoint. Use the NOZERO option to suppress midpoints with no observations.
GROUP= also produces a group axis that lists the values that distinguish the groups. The group axis has no axis line but displays the group variable name or label. To modify the group axis, assign an AXIS definition with the GAXIS= option.
In horizontal bar charts, the group axis is to the left of the midpoint axis and the groups are arranged from top to bottom, starting with the lowest value at the top.
In vertical bar charts, the group axis is below the midpoint axis and the groups are arranged from left to right starting with the lowest value at the left. If the group label in a vertical bar chart is narrower than all the bars in the group, brackets are added to the label to emphasize which bars belong in each group. Group brackets are not displayed if the space between the group values is less than one and one-half character cells. Use the NOBRACKETS option in the AXIS statement to suppress the group brackets.
Featured in: | Creating Bar Charts with Drill-down for the Web |
GSPACE= is ignored unless you also use the GROUP= option. By default, the GCHART procedure calculates group spacing based on size of the axis area and the number of bars in the chart.
If the requested spacing results in a chart that is too large to fit in the space available for the midpoint axis, an error message is written to the SAS log and no chart is produced.
Featured in: | Creating Bar Charts with Drill-down for the Web |
If the bars are subgrouped, only the following statistics are valid:
With subgroups, PERCENT displays the percent contribution of each subgroup to the midpoint value of the bar, based on frequency. The PERCENT values for each subgroup total the percent contribution of the bar to the whole. For example, if the percent contribution of the whole bar is 60%, the PERCENT statistic for all the subgroups in that bar will total 60%. To calculate PERCENT based on the SUMVAR= variable, use the FREQ= and TYPE= options. For details, see Calculating Weighted Statistics.
SUBPCT displays the percent contribution of each subgroup to the total bar. The SUBPCT values for each subgroup total the percent contribution to the whole bar. Because of rounding, the total of the percents may not equal 100.
Only one type of statistic can be printed inside the bars, but you can specify a second statistic with OUTSIDE=.
See also: | About Chart Statistics for a complete description of statistic types |
Featured in: | Subgrouping a 3D Vertical Bar Chart Creating Bar Charts with Drill-down for the Web |
LEGEND= is ignored if
To create a legend based on the chart midpoints instead of the subgroups, use the chart variable as the subgroup variable:
hbar city / subgroup=city;
See also: | LEGEND Statement and SUBGROUP= option |
Featured in: | Subgrouping a 3D Vertical Bar Chart |
See also: | About Midpoints and AXIS Statement |
Featured in: | Subgrouping a 3D Vertical Bar Chart |
Featured in: | Generating Error Bars in a Horizontal Bar Chart |
n <...n> | |
n TO n <BY increment> | |
n<...n> TO n <BY increment> <n <...n>> |
If a numeric variable has an associated format, the specified values must be the unformatted values.
By default, numeric variable values are treated as continuous (if you omit the DISCRETE option), and
If you include the DISCRETE option, each value in value-list specifies a unique numeric value.
'value-1' <...'value-n'> |
If a character variable has an associated format, the specified values must be the formatted values.
For a complete description of value-list, see the ORDER= option in the AXIS statement.
If the value-list for either type of variable specifies so many midpoints that the axis values overwrite each other, the values may be unreadable. In this case the procedure writes a warning to the SAS log. On many devices, this problem can be corrected by either adjusting the size of the text with the HTEXT= graphics option or by increasing the number of cells in your graphics display using the HPOS= and VPOS= graphics options.
The ORDER= option in the AXIS statement overrides the order specified in the MIDPOINTS= option. The bar chart statement options ASCENDING and DESCENDING also override both MIDPOINTS= and ORDER= in the AXIS statement.
See also: | About Midpoints |
Featured in: | Controlling Midpoints and Statistics in a Horizontal Bar Chart |
MINOR= in a bar chart statement overrides the number of minor tick marks specified in the MINOR= option in an AXIS definition assigned to the response axis with the RAXIS= option.
Featured in: | Creating Bar Charts with Drill-down for the Web |
To remove selected axis elements such as lines, values or labels, use specific AXIS statement options.
NOAXIS does not suppress either the default frame or an axis area fill requested by the CFRAME= option. To remove the axis frame or the 3D backplane, use the NOFRAME option in the procedure. To remove the horizontal or vertical axis planes, use the NOPLANE option in the AXIS statement.
Note: If a bar is
omitted and if you have also specified bar labels with the VALUE= option in
an AXIS statement, the labels may be shifted and not displayed with the correct
bar.
Featured in: | Creating Bar Charts with Drill-down for the Web |
Only one type of statistic can be printed outside the bars, but you can specify a second statistic with INSIDE=.
See also: | About Chart Statistics for a complete description of statistic types |
Featured in: | Subgrouping a 3D Vertical Bar Chart Creating Bar Charts with Drill-down for the Web |
Note: If you use the SUBGROUP= option and specify a PATTERNID= value other than
SUBGROUP, the bar segments use the same pattern and are indistinguishable.
See also: | Controlling Bar Chart Patterns and Colors |
Featured in: | Subgrouping a 3D Vertical Bar Chart and Creating Bar Charts with Drill-down for the Web |
You can specify negative values, but negative values are reasonable only when TYPE=SUM or TYPE=MEAN and one or more of the sums or means are less than 0. Frequency and percentage values are never less than 0.
For lists of values, a separate major tick mark is created for each individual value. A warning message is written to the SAS log if the values are not evenly spaced.
If the values represented by the bars are larger than the highest tick mark value, the bars are truncated at the highest tick mark.
If you use a BY statement with the PROC GCHART statement, the same response axes are produced for each BY group when RAXIS=value-list is used or if there is an ORDER= list in the AXIS statement assigned to the response axis.
See also: | AXIS Statement |
Featured in: | Subgrouping a 3D Vertical Bar Chart and Creating Bar Charts with Drill-down for the Web |
Values can be listed in any order, but should be within the range of values represented by the response axis. A warning is written to the SAS log if any of the points are off of the axis, and no reference line is drawn for such points. You can use the AUTOREF option to draw reference lines automatically at all of the major tick marks.
By default, reference lines in 3D bar charts are drawn on the back plane of the axis. To draw the reference lines in front of the bars, use the FRONTREF option.
The COUTLINE= option is not valid when SHAPE=CYLINDER.
Featured in: | Creating Bar Charts with Drill-down for the Web |
SPACE= is ignored if the specified spacing requests a chart that is too large to fit in the space available for the midpoint axis, and a warning message is issued.
Featured in: | Subgrouping a 3D Vertical Bar Chart and Creating Bar Charts with Drill-down for the Web |
If PATTERNID=SUBGROUP (the default setting), each segment is filled with a different pattern and a legend that provides a key to the patterns is automatically generated. If the value of PATTERNID= is anything other than SUBGROUP, the segments are all the same color, the legend is suppressed, and the subgrouping effect is lost.
By default the legend appears at the bottom of the chart. To modify the legend, assign a LEGEND definition with the LEGEND= option. To suppress the legend, specify NOLEGEND.
See also: | LEGEND Statement |
Featured in: | Subgrouping a 3D Vertical Bar Chart, Creating Bar Charts with Drill-down for the Web and Controlling Midpoints and Statistics in a Horizontal Bar Chart |
When you use SUMVAR=, the TYPE= option must be either SUM or MEAN. With SUMVAR=, the default is TYPE=SUM.
Featured in: | Specifying the Sum Statistic in Bar Charts and Generating Error Bars in a Horizontal Bar Chart |
Because you cannot use TYPE=FREQ, TYPE=CFREQ, TYPE=PERCENT, or TYPE=CPERCENT with SUMVAR=, you must use FREQ= to calculate percentages, cumulative percentages, frequencies, or cumulative frequencies based on a sum. See also Calculating Weighted Statistics.
If you specify TYPE=MEAN and use the SUBGROUP= option, the height or length of the bar represents the mean for the entire midpoint. The subgroup segments are proportional to the subgroup's contribution to the sum for the bar. See also SUBGROUP=.
See also: | About Chart Statistics for a complete description of statistic types |
Featured in: | Generating Error Bars in a Horizontal Bar Chart |
vbar site / width=1.5;
If the requested bar width results in a chart that is too large to fit in the space available for the midpoint axis, the procedure issues a warning in the log and ignores the WIDTH= specification. If the specified width is too narrow, the procedure may display the midpoint values vertically.
Featured in: | Subgrouping a 3D Vertical Bar Chart |
The Chart Statistic and the Response Axis |
Logarithmic axes can be specified with the AXIS statement. See AXIS Statement for a complete discussion.
About the Table of Statistics in Horizontal Bar Charts |
To change the column labels for any statistic in the table, use one or more of the statistic column label options: FREQLABEL=, CFREQLABEL=, PERCENTLABEL=, CPERCENTLABEL=, SUMLABEL=, and MEANLABEL=.
To control the font and size of the text in the table of statistics, use the HTEXT= and FTEXT= graphics options.
Ordering and Selecting Midpoints |
To rearrange character or discrete numeric midpoint values or to select ranges for numeric values, use the MIDPOINTS= option. Remember that although changing the number of midpoints for numeric variables may change the range of values for individual midpoints, it does not change the range of values for the chart as a whole. For details, see About Midpoints.
Like MIDPOINTS=, the ORDER= option in the AXIS statement can rearrange the order of the midpoints or suppress the display of discrete numeric or character values. However, ORDER= cannot calculate the midpoints for a continuous numeric variable, or exclude values from the calculations. For details, see the description of the ORDER= option.
Controlling Bar Chart Patterns and Colors |
Each bar in a bar chart is filled with a pattern. By default, the procedure
Note: 3D bar charts always uses solid patterns.
If you use the device's default colors and the first color in the list is either black or white, the procedure does not create a pattern in that color. If you specify a colors list with the COLORS= graphics option, the procedure uses all the colors in the list to generate the patterns.
See About Patterns
for more information on how the GCHART procedure assigns default patterns
and outlines.
To override the default patterns and select fills and colors for the bars or bar segments, use the PATTERN statement. Only bar/block patterns are valid; all other pattern fills are ignored. For a complete description of all bar/block patterns, see VALUE= in PATTERN Statement.
Whenever you use PATTERN statements, the default pattern
outline color changes to SAME. That is, the outline color is the same as the
fill color. To specify the outline color, use the COUTLINE= option (see COUTLINE=).
Instead of changing the pattern for each subgroup, you
can change the pattern for each midpoint, each group, or each BY group by
changing the value of PATTERNID=. See the PATTERNID= option for details.
By default, axis elements use the first color in the colors list or the colors that are specified by AXIS statement color options. However, action statement options can also control the color of the axis lines, text, and frame.
To change the color of... | Use this option... |
the axis text | CTEXT= |
the axis lines | CAXIS= |
the area within the frame | CFRAME= |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.