Chapter Contents

Previous

Next
The GCHART Procedure

PIE, PIE3D, and DONUT Statements


Create pie or donut charts in which the size of a pie slice represents the value of the chart statistic for that category of data in relation to the total chart statistic for all categories.

Requirements: At least one chart variable is required.
Global statements: LEGEND, PATTERN, TITLE, FOOTNOTE
Supports: Drill-down functionality



Description

The PIE, PIE3D, and DONUT statements specify the variable or variables that define the categories of data to chart. These statements automatically

You can use statement options to select or order the midpoints (slices), to change the type of chart statistic, and to modify the appearance of the chart, including the content and position of the slice labels, and patterns used by the slices. You can also specify additional variables by which to group, subgroup, or sum the data. Statement options can also produce special effects, such as exploded or invisible slices.

Donut and pie charts allow grouping and subgrouping. Grouping creates two or more separate pie or donut charts that display in rows or columns on one graph. Subgrouping creates a separate ring of slices within the circle for each value of the subgroup variable. The concentric rings of the subgrouped pie or donut chart make it easy to compare slice values between subgroups.

In addition, you can use global statements to modify patterns and legends, as well as add titles, footnotes, and notes to the chart. You can also use an Annotate data set to enhance the chart.

Syntax

PIE | PIE3D | DONUT chart-variable(s) </ option(s);>

option(s) can be one or more options from any or all of the following categories:


Required Arguments

chart-variable(s)
specifies one or more variables that define the categories of data to chart. Each chart variable draws a separate chart. All variables must be in the input data set. Separate multiple chart variables with blanks.
See also: About Chart Variables


Options

Options in a PIE, PIE3D, or DONUT 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.

ACROSS=number-of-columns
draws number-of-columns pies across the procedure output area. ACROSS is ignored unless you also use the GROUP= option. By default, ACROSS=1.

If number-of-columns calls for more pies than fit horizontally in the graphics output area, no pies are drawn and an error message is written to the SAS log.

If the DOWN= option also is used, the pies are drawn in left-to-right and top-to-bottom order.
Featured in: Assigning Patterns and Identifying Midpoints with a Legend

ANGLE=degrees
starts the first slice at the specified angle. A value of 0 for degrees corresponds to the 3 o'clock position. Degrees can be either positive or negative. Positive values move the starting position in the counterclockwise direction; negative values move the starting position clockwise. By default, ANGLE=0. Successive slices are drawn counterclockwise from the starting slice.

ANNOTATE=Annotate-data-set
ANNO=Annotate-data-set
specifies a data set to annotate charts produced by the PIE, PIE3D, or DONUT statement.

Note:   Annotate coordinate systems 1, 2, 7, and 8 (data system coordinates) are not valid with pie or donut charts.  [cautionend]
See also: The Annotate Data Set

ASCENDING
arranges the slices in ascending order of the value of the chart statistic. By default, slices are arranged in ascending order of midpoint value, without regard to size. ASCENDING reorders the slices from smallest to largest. The OTHER slice is still last regardless of its size.

If you also use the GROUP= option, the reordering is performed separately for each group, so the order of the midpoint values may be different for each pie or donut.

ASCENDING overrides any midpoint order that is specified with the MIDPOINTS= option.

CFILL=fill-color
specifies one color for all patterns in the chart, regardless of whether the fill is solid or hatch. For the PIE3D statement, the fill is always solid. For the PIE and DONUT statements, if no pattern is specified on the PATTERN statement or with the FILL= option, the procedure starts with the default solid fill and then, beginning with P2N0, uses each default pie hatch pattern with the specified color. For the outline color, the procedure uses the foreground color, which is the first color in the colors lists. Use COUTLINE= to specify a different outline color. CFILL= overrides any other pattern color specification and controls the color of all slices.
See also: Controlling Bar Chart Patterns and Colors and About Patterns
Featured in: Ordering and Labeling Slices in a Pie Chart

CLOCKWISE
draws the slices clockwise starting at the 12 o'clock position. Although this position implies ANGLE=90, you can use ANGLE= to specify a different starting angle.
Featured in: Assigning Patterns and Identifying Midpoints with a Legend

COUTLINE=slice-outline-color | SAME
outlines all slices, rings (subgroups), and legend values (if a legend appears) in the specified color. SAME specifies that the outline color of a slice or a slice segment or a legend value is the same as the interior pattern color.

The default outline color depends on the PATTERN statement:

Note:   If you specify empty patterns (VALUE=PEMPTY in a PATTERN statement), you should not change the outline color from the default value, SAME, to a single color. Otherwise, all of the outlines will be one color and you will not be able to distinguish between the empty areas.  [cautionend]
See also: Controlling Slice Patterns and Colors and About Patterns
Featured in: Specifying the Sum Statistic for a Pie Chart, Subgrouping a Donut or Pie Chart and Assigning Patterns and Identifying Midpoints with a Legend

CTEXT=text-color
specifies the color for all text on the chart that is not otherwise assigned a color. Text includes all slice labels, the chart heading, and group headings if grouping is used. CTEXT= also affects the color of the slice label arrows. See Selecting and Positioning Slice Labels.

If you omit CTEXT=, PROC GCHART searches for a color specification in this order:

  1. the CTEXT= option in a GOPTIONS statement

  2. the first color in the colors list (the default).

The MATCHCOLOR option overrides the CTEXT= option for slice labels.
Featured in: Subgrouping a Donut or Pie Chart and Assigning Patterns and Identifying Midpoints with a Legend

DESCENDING
arranges the slices in descending order of the value of the chart statistic. By default, slices are arranged in ascending order of midpoint value, without regard to size. DESCENDING reorders the slices from largest to smallest. The OTHER slice is still last, regardless of its size.

If you also use the GROUP= option, the reordering is performed separately for each group, so the order of midpoint values may be different for each pie or donut.

DESCENDING overrides any midpoint order that is specified with the MIDPOINTS= option.
Featured in: Assigning Patterns and Identifying Midpoints with a Legend

DESCRIPTION='entry-description'
DES='entry-description'
specifies the description of the catalog entry for the chart. The maximum length for entry-description is 40 characters. The description does not appear on the chart. By default, the GCHART procedure assigns a description of the form PIE (or PIE3D or DONUT) CHART OF variable, where variable is the name of the chart variable.

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:

DISCRETE
treats a numeric chart variable as a discrete variable rather than as a continuous variable. The GCHART procedure creates a separate midpoint and, hence, a separate slice for each unique value of the chart variable. If the chart variable has a format associated with it, each formatted value is treated as a midpoint.

The LEVELS= option is ignored when you use DISCRETE. The MIDPOINTS= option overrides DISCRETE.

DONUTPCT=percent (DONUT only)
specifies the size of the donut hole in percent of the radius of the whole chart. Values of percent range from 0 to 99. By default, DONUTPCT=25.
Featured in: Subgrouping a Donut or Pie Chart

DOWN=number-of-rows
draws number-of-rows pies vertically in the procedure output area. The DOWN= option is ignored unless you also use the GROUP= option. By default, DOWN=1.

If number-of-rows calls for more pies than fit vertically in the graphics area of the output device, no pies are drawn and an error message is written to the SAS log.

If you also use the ACROSS= option, the pies are drawn in left-to-right and top-to-bottom order.

EXPLODE=value-list
pulls the specified slices slightly out from the rest of the pie for added emphasis. Value-list is the list of midpoint values for the slices to be exploded. See the MIDPOINTS= option for a description of value-list.

The values in the value list must match the existing midpoints exactly, including the case of character midpoints. Any values in the list that do not correspond to existing midpoints are ignored.

When you use EXPLODE=, the radius is reduced to allow room for exploded slices.

EXPLODE= does not work with subgroups.
Featured in: Specifying the Sum Statistic for a Pie Chart

FILL=SOLID | X
specifies the fill pattern for all slices in the chart:

SOLID S
rotates a solid fill through the colors list as many times as necessary. This is the default.

X
rotates a single hatch pattern through the colors list as many times as necessary. PIE3D does not support FILL=X.

If you use default device colors (the COLORS= option is omitted), the fill skips the first color in the colors list.

FILL= overrides any pattern that is specified in PATTERN statements.

By default, the outline color is the first color in the colors list. If PATTERN statements are used to specify colors, the slice outline color matches the slice fill color.

By default, the fill patterns take the colors from the current colors list in rotation. If any PATTERN statements have been defined, the colors in the PATTERN definitions are used, in order, before the default color rotation.
See also: Controlling Bar Chart Patterns and Colors and PATTERN Statement

FREQ=numeric-variable
specifies a variable whose values weight the contribution of each observation in the computation of the chart statistic. Each observation is counted the number of times specified by the value of numeric-variable for that observation. If the value of numeric-variable is missing, 0, or negative, the observation is not used in the statistic calculation. Noninteger values of numeric-variable are truncated to integers.

FREQ= is valid with all chart statistics.

Because you cannot use TYPE=PERCENT or TYPE=FREQ with the SUMVAR= option, you must use FREQ= to calculate percentages and frequencies based on a sum.
See also: Calculating Weighted Statistics

GROUP=group-variable
organizes the data according to values of group-variable and produces a separate pie (or donut) chart for each unique value of group-variable. Group-variable can be either character or numeric and is always treated as a discrete variable. Missing values for group-variable are treated as a valid group. By default, each group includes only those midpoints with nonzero chart statistic values.

By default, the charts are produced in ascending order of group variable value and each is drawn on a separate page or display. Therefore, the effect of GROUP= is essentially the same as using a BY statement except that GROUP= causes the midpoints with the same value to use the same color and fill pattern. To place more than one pie on a page or display, use the ACROSS= or DOWN= options, or both.
See also: BY Statement
Featured in: Grouping and Arranging Pie Charts

HTML=variable
identifies the variable in the input data set whose values create links in the HTML file that is created by the ODS HTML statement. These links are associated with an area of the chart and point to the data or graph that you wish to display when the user drills down on the area.

HTML_LEGEND=variable
identifies the variable in the input data set whose values create links in the HTML file created by the ODS HTML statement. These links are associated with a legend value and point to the data or graph that you wish to display when the user drills down on the value.

INVISIBLE=value-list
makes the specified slices invisible, as if they had been removed from the pie. Labels are not printed for invisible slices. Value-list is the list of midpoint values for the invisible slices. See the MIDPOINTS= option for a description of value-list.

The values in the value list must match the existing midpoints exactly, including the case of character midpoints. Any values in the list that do not correspond to existing midpoints are ignored.

JSTYLE
arranges the midpoints in descending order of the statistic value and draws the slices clockwise starting at the 12 o'clock position. The JSTYLE option has the same effect as specifying both the DESCENDING and CLOCKWISE options.

LABEL=(text argument(s)) (DONUT only)
defines the text that is displayed in the donut hole. Text-argument(s) defines the text or the appearance of the label, or both. Text-argument(s) can be one or more of the following:

'text-string'
provides the text of the label. Enclose each string in quotation marks. Separate multiple strings with blanks.

text-description-suboption
modifies a characteristic such as the font, color, or size of the text string(s) that follows it. Text-description-suboption can be
ANGLE=degrees
COLOR=color
FONT=font
HEIGHT=text-height <units>
JUSTIFY=LEFT | CENTER | RIGHT
ROTATE=degrees

See Text Description Suboptions for a complete description.

Specify as many text strings and text description suboptions as you want, but enclose them all in one set of parentheses.
Featured in: Subgrouping a Donut or Pie Chart

LEGEND | LEGEND=LEGEND<1...99>
generates a legend for the slice names (midpoint values) instead of printing them beside the slices. The legend displays each slice name and its associated pattern. This option also suppresses the display of the chart statistic values. To display the chart statistics, use the VALUE= option.

If you use the SUBGROUP= option, the legend is automatically generated. However, because patterning is always by midpoint, the legend still describes the midpoint values, not the subgroups.

Note:   If you request a legend and the slices use hatch patterns, the patterns in the slices are oriented to be visually equivalent to the legend.  [cautionend]

Specifying LEGEND=LEGENDn assigns the specified LEGEND statement to the legend.
See also: LEGEND Statement and SUBGROUP= option
Featured in: Subgrouping a Donut or Pie Chart Assigning Patterns and Identifying Midpoints with a Legend

LEVELS=number-of-midpoints
specifies the number of midpoints for a numeric chart variable. The range for each midpoint is calculated automatically. LEVELS= is ignored if

MATCHCOLOR
uses the slice pattern color for all slice labels. MATCHCOLOR overrides the color that is specified in the CTEXT= option.

MIDPOINTS=value-list
specifies the midpoint values for the slices. The way you specify value-list depends on the type of variable:

For a complete description of value-list, see the ORDER= option in the AXIS statement.

Midpoints that represent small percentages are collected into a generic midpoint named OTHER. See the OTHER= option and the OTHERLABEL= option for more information.
See also: About Midpoints
Featured in: Ordering and Labeling Slices in a Pie Chart

MIDPOINTS=OLD
tells the GCHART procedure to calculate default midpoints using the algorithm used in Release 82.4 and Version 5 of SAS/GRAPH. The MIDPOINTS=OLD option is ignored unless the numeric chart variable is numeric type.

MISSING
accepts a missing value as a valid midpoint for the chart variable. By default, observations with a missing value are ignored. Missing values are always valid for the group and subgroup variable.

NAME='entry-name'
specifies the name of the catalog entry for the graph. The maximum length for entry-name is eight characters. The default name is GCHART. If the name duplicates an existing entry name, SAS/GRAPH software adds a number to the duplicate name to create a unique name- for example, GCHART1.

NOGROUPHEADING
suppresses the headings that are normally printed above each pie when you use the GROUP= option.

NOHEADING
suppresses the heading that is normally printed at the top of each page or display of output.
Featured in: Subgrouping a Donut or Pie Chart

NOLEGEND
suppresses the legend that is automatically generated by the SUBGROUP= option. NOLEGEND is ignored if the SUBGROUP= option is not used.

OTHER=percent-of-total
collects all midpoints with chart statistic values less than or equal to percent-of-total into a generic midpoint named OTHER. The value of percent-of-total can be 0 to 100; the default value is 4. Therefore, any slice that represents 4 percent or less of the total is put in the OTHER category.

Note:   If you specify a small value for percent-of-total, the GCHART procedure may not be able to label all of the small slices.  [cautionend]

The OTHER slice is the last slice in the pie, regardless of the order of the slices. (In other words, it is the slice immediately before the starting slice.)

If only one midpoint falls into the OTHER category, its slice is displayed in its normal position in the pie and retains its original label. For example, suppose a pie has these slices and percent values: Coal 35%, Gas 15%, Hydro 5%, and Oil 45%. If you specify OTHER=5, Hydro remains the third slice instead of becoming the last slice.
Featured in: Assigning Patterns and Identifying Midpoints with a Legend and Grouping and Arranging Pie Charts

OTHERLABEL='text-string'
specifies a text string up to 16 characters for the label for the OTHER slice. The default label is OTHER.
Featured in: Assigning Patterns and Identifying Midpoints with a Legend

PERCENT=ARROW | INSIDE | NONE | OUTSIDE
prints the percentage represented by each slice using the specified labeling method. For a description of the option values, see Selecting and Positioning Slice Labels. By default, PERCENT=NONE (percentage is not displayed).

Whether the slice percent displays with or without decimal places, depends on the range of values across the chart.The only way to control the appearance of these values is to calculate the percentage with a DATA step or statistical procedure and use the resulting data set as input to the GCHART procedure. Assign the variable that contains the calculated percentages to the SUMVAR= option.
Featured in: Ordering and Labeling Slices in a Pie Chart and Grouping and Arranging Pie Charts

SLICE=ARROW | INSIDE | NONE | OUTSIDE
controls the position and style of the slice name (midpoint value) for each slice. For a description of the option values, see Selecting and Positioning Slice Labels. By default, SLICE=OUTSIDE (the name is outside of the slice).
Featured in: Ordering and Labeling Slices in a Pie Chart and Grouping and Arranging Pie Charts

SUBGROUP=subgroup-variable
divides the chart into concentric rings according to the values of subgroup-variable. Subgroup-variable can be either character or numeric and is always treated as a discrete variable.

The width of the rings, which is the same for each subgroup, is determined by the radius of the pie and the size of the donut hole, if any.

By default, the subgroup rings are ordered from the outside in, alphabetically (if character) or numerically (if numeric). If the JSTYLE option is also used, the order of the slices within the subgroups is determined by the outermost subgroup. Any inner subgroup that contains a value that is not in the outer subgroup, places the new slice for that value either last or just before the "other" slice, if one is present. That slice order is continued for any remaining subgroups.

Each ring is labeled with its subgroup value; labels are placed to the right of the chart. If the GROUP= option is also used, only the first (upper left) chart on each page is labeled.

By default the subgroups are outlined in the foreground color. To specify an outline color, use the COUTLINE= option.

SUBGROUP= automatically generates a legend for the midpoint values (not the subgroup values) and suppresses display of the chart statistic. By default the legend appears at the bottom of the chart. To modify the legend, assign a LEGEND definition. To suppress the legend, specify NOLEGEND. To display the chart statistic, use the VALUE= option.

If EXPLODE is also used, it is ignored.
See also: Controlling Bar Chart Patterns and Colors and LEGEND Statement
Featured in: Subgrouping a Donut or Pie Chart and Ordering and Labeling Slices in a Pie Chart

SUMVAR=summary-variable
specifies a numeric variable for sum or mean calculations. The GCHART procedure calculates the sum or, if requested, the mean of numeric-variable for each midpoint. The resulting statistics are represented by the size of the slice and displayed beside of each slice.

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 for a Pie Chart

TYPE=statistic
specifies the chart statistic.

Because you cannot use TYPE=FREQ or TYPE=PERCENT with SUMVAR=, you must use FREQ= to calculate percentages or frequencies based on a sum. See also Calculating Weighted Statistics.
See also: About Chart Statistics

VALUE=ARROW | INSIDE | NONE | OUTSIDE
controls the position and style of the slice value (chart statistic) for each slice. For a description of the option values see Selecting and Positioning Slice Labels. By default, VALUE=OUTSIDE (the value is outside the slice).
Featured in: Ordering and Labeling Slices in a Pie Chart and Assigning Patterns and Identifying Midpoints with a Legend

WOUTLINE=slice-outline-width
specifies the width of the outline in pixels. WOUTLINE= affects both the slice and the subgroup outlines.


Text Description Suboptions

The LABEL= option in the DONUT statement uses text description suboptions to change the color, height, justification, font, and angle of the following text string(s).

ANGLE=degrees
A=degrees
specifies the angle at which the baseline of the text string(s) is rotated with respect to the horizontal. A positive value for degrees moves the baseline counterclockwise; a negative value moves it clockwise. By default, ANGLE=0 (horizontal).

COLOR=color
C=color
specifies the color for the text string(s). The COLOR= suboption stays in effect until another COLOR= specification is encountered. If you omit COLOR=, LABEL= uses the first color in the colors list. It ignores the CTEXT= graphics option. See SAS/GRAPH Colors for details on specifying color.

FONT=font
F=font
specifies the font for the text string(s). If you omit FONT=, LABEL= uses the font that is specified by the FTEXT= graphics option. If no font is specified, it uses the default hardware font, NONE. See SAS/GRAPH Fonts for details on specifying font.

HEIGHT=text-height <units>
H=text-height <units>
specifies the height of the text string(s). Text-height is the number of units. If you omit HEIGHT=, LABEL= uses the height that is specified by the HTEXT= graphics option. If no text height is specified and if the default text height is too large for the donut hole, the size of the label is reduced to fit. Units can be CELLS | CM | IN | PCT | PT. If you omit units, HEIGHT= uses the unit that is specified by the GUNIT= graphics option, or the default unit, CELLS.

JUSTIFY=LEFT | CENTER | RIGHT
J=L | C | R
specifies the alignment of the text string(s). By default, JUSTIFY=CENTER.

ROTATE=degrees
specifies the angle at which each character is rotated with respect to the baseline of the text string. The angle is measured from the current text baseline angle specified by the ANGLE= suboption. A positive value for degrees rotates the character counterclockwise; a negative value rotates it clockwise. By default, ROTATE=0 (parallel to the baseline).


Selecting and Positioning Slice Labels

By default, each slice is labeled with its midpoint value (slice name) and its chart statistic value (slice value), which are printed outside of the slice. You can control where and how these labels are displayed with the SLICE= and VALUE= options, respectively. In addition, each slice can display the percentage its midpoint contributes to the total chart statistic(slice percent). Use the PERCENT= option to request slice percent.

The SLICE=, VALUE=, and PERCENT= options use the same values:

ARROW
places the text outside the slice and connects the text to the slice with a line. This labeling method reduces the radius of the pie. The arrow uses the color that is specified by CTEXT= in the PIE, PIE3D, or DONUT statement. If CTEXT= is omitted, the arrow uses the first color in the colors list.

INSIDE
places the text inside the slice. The label overlays the slice fill patterns. This labeling method increases the radius of the pie.

NONE
suppresses the text.

OUTSIDE
places the text outside of the slice.

Slice Labeling Methods illustrates these values.

Slice Labeling Methods

[IMAGE]

The SLICE= and VALUE= options are dependent on each other. If you specify only VALUE= or only SLICE=, the other option automatically uses the same labeling method. PERCENT= is independent of these two.

Be careful about the combinations that you specify. For example, if you specify PERCENT=ARROW and VALUE=OUTSIDE, the line that connects the percentage information to each slice may overlay the statistic value.

If your pie has many slices, the labels may overlap, particularly if there are several small slices together. You can correct the overlapping labels by using


Controlling Slice Patterns and Colors

Pie and donut charts are always patterned by midpoint. Even when you specify subgrouping, the patterning method does not change from midpoint to subgroup.

Default patterns and outlines

Each slice in a pie or donut chart is filled with a pattern. By default, the procedure

See About Patterns for more information on how the GCHART procedure assigns default patterns and outlines.

Controlling patterns

You can control slice patterns and their outlines in several ways.

See About Patterns for more information on how the GCHART procedure uses patterns and outlines. See PATTERN Statement for a description of default pie/star patterns.


Modifying the Statistic Heading and the Group Heading

By default, the procedure prints a heading at the top of each pie (or donut) chart that indicates the type of statistic charted and the name of the chart variable- for example, SUM of SALES by SITE. You can suppress this heading with the NOHEADING option.

When you use the GROUP= option, a heading is printed above each pie indicating the name of the group variable and its value for the particular pie- for example, SITE=Paris. You can suppress these headings with the NOGROUPHEADING option. You can also suppress the variable name SITE= so that only the value Paris remains. To do this, use a LABEL statement and assign a null value to the variable name, for example,

label site='00'x;

Because the AXIS statement cannot be used by the PIE, PIE3D, and DONUT statements, you should use the FTEXT= and HTEXT= graphics options to control the font and height of text on the chart. Increasing the value of the HTEXT= graphics option decreases the size of the pie if any slice labels are positioned outside.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.