Example Program and Statement Details

Example Graph

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

Example Program

proc template;
define statgraph simplepie;
  begingraph;
    entrytitle "Car Models by Origin";
    layout region;
      piechart category=origin / datalabellocation=outside;
    endlayout;
  endgraph;
end;
run;
proc sgrender data=sashelp.cars 
              template=simplepie;
run;

Statement Summary

The PIECHART statement is used in a LAYOUT REGION, LAYOUT GRIDDED, or LAYOUT LATTICE block. It cannot be used in LAYOUT OVERLAY block because a pie chart does not have axes. The input data for the PIECHART statement is raw, unsummarized input data. The PIECHART performs discrete binning for the CATEGORY column and calculates appropriate summarization statistics (sum, mean, and so on) based on the setting for the STAT= option.
By default, the fill color of each pie slice is derived from the Color attribute of the GraphData1–GraphDataN style elements. When the number of categories exceeds the number of GraphDataN elements, the GraphData1–GraphDataN colors are repeated, but the shade of each color is varied on each cycle. The shade variations alternate between one shade lighter and one shade darker on each cycle. The fill color of the “other” slice (if shown) is derived from the Color attribute of the GraphOther style element.
The default order of the pie slices depends on the data type of the CATEGORY values:
  • For numeric data, the slices appear in the ascending order of the unformatted data values.
  • For discrete data, the slices appear in data order.
You can use the START= and CATEGORYDIRECTION= options to control the pie slice positions and display order.
By default, the pie slices are labeled with the CATEGORY and RESPONSE values, which are displayed inside the slices. You can use the DATALABELLOCATION= and DATALABELCONTENT= options to control where the pie slices are labeled and the label content.
By default if two or more slices take up less than 4% of a pie, an “other” slice is created by consolidating those small slices. To change the default criteria, use the OTHERSLICE= and OTHERSLICEOPTS= options. The calculated “other” slice is displayed as the last slice in the pie, and as the last legend entry for the pie. If a category value is the same as the “other” slice label, two slices might be displayed with the same label ("Other" by default) and different fill attributes. In that case, both slices are represented in the pie legend.
To create a pie slice for missing CATEGORY values, specify INCLUDEMISSINGDISCRETE=TRUE in the BEGINGRAPH statement. The fill color of the missing category slice is assigned the fill color from the GraphMissing style element except when a user-defined format is applied to the category value. In that case, the missing category slice is assigned the fill color from a GraphData1–GraphDataN style element in data order instead.
Note: The PIECHART statement does not honor the MISSING= system option. Regardless of the MISSING= system option value, unless a user-defined format is applied to the value, the default missing-numeric-value character (.) is used to depict missing numeric values.

Arguments

CATEGORY=column | discrete-attr-var | expression
(required argument) specifies the column for the category values. Duplicated values of CATEGORY are summarized into a unique value. All values are treated as discrete.
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.
RESPONSE=numeric-column | expression
(optional argument) specifies response values that are read from a numeric column or an expression.

Options

Statement Option
Description
Specifies whether to display the pie slices in counterclockwise or clockwise sequence.
Specifies the color and font attributes of the data labels.
Specifies the information to display in the slice labels.
Specifies whether to display the slice labels within the pie slices or outside of the pie circumference.
Enhances the visual appearance of the filled pie slices.
Specifies the degree of the transparency of all pie slices, outlines, and text.
Specifies whether to display outlined pie slices, filled pie slices, or outlined and filled pie slices.
Specifies the appearance of the filled pie slices.
Creates a separate concentric annulus (or stacked cylinders) for each unique group value of the specified column.
Specifies a dimension for the optional gap that can be displayed between each annulus of a grouped pie.
Specifies text attributes, location, and other options for displaying group labels.
Specifies whether missing values of the GROUP column are included in the pie.
Specifies the label fitting policy to be used if a particular label does not fit within the pie slice.
Assigns a name to a plot statement for reference in other template statements.
Specifies whether to consolidate smaller pie slices into a single slice that represents “other” values that are in the data, or whether to display those smaller slices as separate pie slices.
Specifies the properties of the “other” slice.
Specifies the properties of the pie and slice outlines.
Specifies which degree between 0 and 360 serves as the starting position for the first pie slice.
Specifies the statistic to be computed.
Specifies the information to display when the cursor is positioned over a pie slice.
Specifies display formats for information defined by the tooltip roles.
Specifies display labels for information defined by the tooltip roles.
Specifies an HTML page to display when a pie slice is selected.
CATEGORYDIRECTION= COUNTERCLOCKWISE | CLOCKWISE
specifies whether to display the pie slices in counterclockwise or clockwise sequence.
Default: COUNTERCLOCKWISE
See Also: The START= option for controlling the starting angle for the first pie slice.
DATALABELATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the slice labels. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphValueText style element.
DATALABELCONTENT= ALL | STANDARD | NONE | (content-options)
specifies the information to display in the slice labels.
Default:
  • When STAT=PCT, the default is (CATEGORY PERCENT).
  • For all other values of the STAT= option, the default is STANDARD.
ALL
displays all available information
STANDARD
equivalent to specifying the two content-options CATEGORY and RESPONSE
NONE
does not display slice labels
(content-options)
a list of options, enclosed in parentheses, that must include at least one of the following:
CATEGORY—displays the CATEGORY value
PERCENT—the display depends on the setting for the STAT= option:
  • if STAT=FREQ or STAT=PCT, displays the PERCENT value
  • if STAT=MEAN or STAT=SUM, displays nothing
RESPONSE—displays the statistic that is requested in the STAT= option.
Note: The position of the labels is adjusted to prevent the labels from overlapping.
DATALABELLOCATION = AUTO | INSIDE | OUTSIDE | CALLOUT
specifies whether to display the slice labels within the pie slices or outside of the pie circumference.
Pie Label Locations
Default: AUTO
AUTO
automatically selects either INSIDE, OUTSIDE, or CALLOUT to optimize the label position
INSIDE
locates the slice labels inside the pie slices.
Note: If a particular label does not fit within the pie slice, the fit policy takes effect (set by the LABELFITPOLICY= option).
OUTSIDE
locates the slice labels outside of the pie circumference.
CALLOUT
locates the slice labels outside of the pie circumference and draws a callout from the label to its slice.
DATASKIN= NONE | PRESSED | SHEEN | CRISP | GLOSS | MATTE
enhances the visual appearance of the filled pie slices.
Pie Charts with Data Skins
Default: NONE
Requirement: For this option to have any effect, DISPLAY=FILL must be in effect. Otherwise, this option is ignored.
Interaction: The appearance of the data skin is based on the FILLATTRS= color.
Interaction: When a data skin is applied, all slice outlines are set by the skin, and the OUTLINEATTRS= option is ignored.
DATATRANSPARENCY=number
specifies the degree of the transparency of all pie slices, outlines, and text.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Tip: The FILLATTRS= option can be used to set transparency for just the pie slices. The OTHERSLICEOPTS= option can be used to specify transparency for the “other” slice. You can combine this option with FILLATTRS= and with OTHERSLICEOPTS= to set one transparency for the outlines and text but a different transparency for the pie slices. Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
DISPLAY=STANDARD | (display-options)
specifies whether to display outlined pie slices, filled pie slices, or outlined and filled pie slices.
Default: STANDARD
STANDARD
displays outlined, filled pie slices
(display-options)
a list of options, enclosed in parentheses, that must include at least one of the following:
OUTLINE displays outlined pie slices. The default outline properties are set by the GraphOutline style element.
FILL displays filled pie slices with each slice a different color. The default colors are set by the Color attribute of the GraphData1-GraphDataN style elements. The fill color of the “other” slice (if shown) is from the color attribute of the GraphOther style element. If FILL is not specified, an opaque pie is drawn using the background color of the containing layout.
Tip: Use the OUTLINEATTRS= and FILLATTRS= options to control the appearance of the pie slices.
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the appearance of the filled pie slices, excluding the “other” slice. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
Default: The GraphDataDefault:Color style reference.
Interaction: For this option to have any effect, the fill must be enabled by the ODS style or the DISPLAY= option.
Tip: The FILLATTRS= suboption of the OTHERSLICEOPTS= option controls the visual properties of the “other” slice.
Tip: The DATATRANSPARENCY= option sets the transparency for all pie slices, outlines, and text. You can combine this option with DATATRANSPARENCY= to set one transparency for the outlines and text but a different transparency for the pie slices. Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
GROUP=column | expression
creates a separate concentric annulus (or stacked cylinders) for each unique group value of the specified column. The grouped rings are displayed in data order.
Default: no default.
Grouped Pie Chart
Interaction: When this option is used, the unique column values are found and then the slice colors are taken from the GraphData1 - GraphDataN style elements.
Interaction: Missing values in the data can affect the group order. You can use the INCLUDEMISSINGGROUP= option to manage missing group values. In addition, you can use INCLUDEMISSINGDISCRETE=TRUE in the BEGINGRAPH statement to create pie slices for missing CATEGORY values.
Tip: This option creates only rings of pies. To create a grid of pies, specify the PIECHART statement within a LAYOUT LATTICE, LAYOUT DATALATTICE, or LAYOUT DATAPANEL statements.
See Also: The FILLATTRS=, GROUPGAP= , and GROUPLABELOPTS= options.
GROUPGAP= dimension
specifies a dimension for the optional gap that can be displayed between each annulus of a grouped pie.
Default: 0
Restriction: For this option to take effect, the GROUP= option must also be specified.
Interaction: If the specified dimension is too large for the area that is available to the pie chart, unexpected results might occur.
Note: The size of the inner pie remains the same regardless of the GROUPGAP= value.
GROUPLABELOPTS=(grouplabel-options)
specifies text attributes, location, and other options for displaying group labels.
Default: The group label and values are shown as a block of text to the right or left of the pie. Slice labels are moved to the inside of the pie slices. A callout is drawn from each group value to its annulus (or cylinder).
Restriction: For this option to take effect, the GROUP= option must also be specified.
The following grouplabel-options are available. One or more options can be specified as name = value pairs, separated by blanks.
LABEL= AUTO | NONE | "string"
specifies a descriptive label for the GROUP column
Default: AUTO
AUTO The column label of the GROUP= column or the column name of the GROUP= column, if no column label exists.
NONE No label is displayed
"string" The specified string is used
LABELATTRS= style-element | style-element (text-options) | (text-options)
specifies the text properties of the group label. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphLabelText style element.
LOCATION= RIGHT | LEFT
specifies whether the block of text for group labeling appears to the right or left of the pie.
Default: RIGHT
VALUEATTRS=style-element | style-element (text-options) | (text-options)
specifies the text properties of the group values. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphValueText style element.
INCLUDEMISSINGGROUP=boolean
specifies whether missing values of the GROUP column are included in the pie. When INCLUDEMISSINGGROUP=TRUE and missing group values exist in the data, a solid ring or inner pie is added to the pie chart to represent the missing group. The missing group ring or inner pie is assigned a fill color from the GraphData1-GraphDataN style elements in data order.
Default: TRUE
Restriction: For this option to take effect, the GROUP= option must also be specified.
LABELFITPOLICY = NONE | DROP
specifies the label fitting policy to be used if a particular label does not fit within the pie slice.
Default: NONE
NONE
Draw each label regardless of whether it fits within the slice region.
DROP
Drop labels that do not fit within the slice region, but draw labels that do fit.
Tip: This option determines how labels are managed when DATALABELLOCATION=INSIDE and a particular label does not fit within the pie slice.
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.
OTHERSLICE = boolean
specifies whether to consolidate smaller pie slices into a single slice that represents “other” values that are in the data, or whether to display those smaller slices as separate pie slices.
Default: TRUE
Tip: To set the properties of the “other” slice, use the OTHERSLICEOPTS= option.
Details: If this option is set to FALSE, then all unique category values appear as slices. If this option is set to TRUE, then some of the smaller slices might be combined into a single slice, referred to as the “other” slice.
OTHERSLICEOPTS=(other-slice-options)
specifies the properties of the “other” slice. Example:
piechart category=region / name="p"
  datalabelcontent=(percent) datalabellocation=inside
  otherslice=true
  othersliceopts=(type=percent percent=11 label="Other Regions") ;
Control the “other” slice using a percentage
Interaction: This option is ignored if OTHERSLICE=FALSE.
The following other-slice-options are available. One or more options can be specified as name = value pairs, separated by blanks.
TYPE = PERCENT | MAXSLICES
specifies which method to use to determine the size of the “other” slice.
Default: PERCENT
PERCENT Use the percentage that is set by the PERCENT= suboption.
MAXSLICES Use the count that is set by the MAXSLICES= suboption.
MAXSLICES= positive-integer
specifies the maximum number of category values to represent with pie slices. Any remaining values are consolidated into the “other” slice.
Default: 10
Interaction: For this option to have any effect, TYPE=MAXSLICES must also be specified among the suboptions for OTHERSLICEOPTS=.
Interaction: The slices are counted in the order in which they are displayed. This order is affected by the CATEGORYDIRECTION= option.
PERCENT= percent-of-total
collects all category values with response values less than or equal to the specified percent-of-total into the “other” slice.
Default: 4. Any original slice that represents 4% or less of the total is put in the “other” category.
Range: 0 to 100
Interaction: For this option to have any effect, TYPE=PERCENT must also be specified among the suboptions for OTHERSLICEOPTS=..
LABEL= "string"
specifies a label for the “other” slice.
Default: "OTHER"
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the appearance of the “other” slice's area fill. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
OUTLINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the properties of the pie and slice outlines. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphOutlines style element.
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.
START=degrees
specifies which degree between 0 and 360 serves as the starting position for the first pie slice.
Default: 0
Range: 0 to 360
Details: A value of 0 degrees corresponds to the three o'clock position. Degrees can be either positive or negative. Positive values move the starting position counterclockwise, and negative values move the starting position clockwise. By default, successive slices are drawn counterclockwise from the starting slice. You can change the default direction with the CATEGORYDIRECTION= option.
STAT=FREQ | PCT | SUM | MEAN
Specifies the statistic to be computed.
Default:
  • FREQ for pie charts that do not specify the RESPONSE= argument
  • SUM for pie charts that specify the RESPONSE= argument
Available Values:
RESPONSE= Argument Is Not Specified
RESPONSE= Argument Is Specified
FREQ—Frequency count
SUM—Sum
PCT—Percent
MEAN—Mean
Interaction: When STAT=PCT, the default label content is (CATEGORY PERCENT) instead of STANDARD. See DATALABELCONTENT= ALL | STANDARD | NONE | (content-options).
TIP=(role-list)
specifies the information to display when the cursor is positioned over a pie slice. If this option is used, it replaces all the information displayed by default.
Default: The columns assigned to these roles are automatically included in the tooltip information: CATEGORY and RESPONSE.
(role-list)
an ordered, blank-separated list of unique PIECHART roles. PIECHART roles include CATEGORY, RESPONSE, and GROUP. The RESPONSE role represents the computed statistic for the CATEGORY value, based on the statistic that is set by the STAT= option.
The following example displays tooltips for the columns assigned to the roles CATEGORY and RESPONSE:
TIP=(CATEGORY RESPONSE)
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.
Tip: The labels and formats for the TIP variables can be controlled with theTIPLABEL= 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 rolename = format pairs separated by blanks.
TIP=(CATEGORY RESPONSE)
TIPFORMAT=(RESPONSE=5.)
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. Only the roles that appear in the TIP= option are used.
Default: The column label or column name of the variable assigned to the role.
(role-label-list)
a list of rolename = "string" pairs separated by blanks.
TIP=(CATEGORY RESPONSE)
TIPLABEL=(RESPONSE="Frequency")
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.
URL=character-column
specifies an HTML page to display when a pie slice is selected.
Default: no default
character-column
each value of the column must be a valid HTML page reference (HREF). For example, http://www.sas.com/technologies/analytics/index.html.
Requirement: To generate a plot with selectable pie slices, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
The URL value can be blank for some pie slices, meaning that no action is taken when the corresponding slice is selected. The URL value can be the same for any CATEGORY and RESPONSE pairs. In that case, the same action is taken when the pie slices for those pairs are selected.