Syntax: CHART Procedure


Requirement: You must use at least one of the chart-producing statements.

Tip: Supports the Output Delivery System. See Output Delivery System on page 32 for details.

ODS Table Names: See: ODS Table Names on page 196

Reminder: You can use the ATTRIB, FORMAT, LABEL, and WHERE statements. See Chapter 3, Statements with the Same Function in Multiple Procedures, on page 57 for details. You can also use any global statements. See Global Statements on page 18 for a list.

PROC CHART < option(s) >;

  • BLOCK variable(s) </ option(s) >;

  • BY <DESCENDING> variable-1

    • < <DESCENDING> variable-n >

    • <NOTSORTED>;

  • HBAR variable(s) </ option(s) >;

  • PIE variable(s) </ option(s) >;

  • STAR variable(s) </ option(s) >;

  • VBAR variable(s) </ option(s) >;

PROC CHART Statement

PROC CHART < option(s) >;

Options

DATA= SAS-data-set

  • identifies the input SAS data set.

  • Main discussion: Input Data Sets on page 19

  • Restriction: You cannot use PROC CHART with an engine that supports concurrent access if another user is updating the data set at the same time.

FORMCHAR <( position(s) )>= formatting-character(s)

  • defines the characters to use for constructing the horizontal and vertical axes, reference lines, and other structural parts of a chart. It also defines the symbols to use to create the bars, blocks, or sections in the output.

  • position(s)

    • identifies the position of one or more characters in the SAS formatting-character string. A space or a comma separates the positions .

    • Default: Omitting ( position(s) ), is the same as specifying all 20 possible SAS formatting characters, in order.

    • Range: PROC CHART uses 6 of the 20 formatting characters that SAS provides. Table 7.1 on page 184 shows the formatting characters that PROC CHART uses. Figure 7.1 on page 184 illustrates the use of formatting characters commonly used in PROC CHART.

Table 7.1: Formatting Characters Used by PROC CHART

Position

Default

Used to draw

1

Vertical axes in bar charts, the sides of the blocks in block charts, and reference lines in horizontal bar charts. In side-by-side bar charts , the first and second formatting characters appear around each value of the group variable (below the chart) to indicate the width of each group.

2

-

Horizontal axes in bar charts, the horizontal lines that separate the blocks in a block chart, and reference lines in vertical bar charts. In side-by-side bar charts, the first and second formatting characters appear around each value of the group variable (below the chart) to indicate the width of each group.

7

+

Tick marks in bar charts and the centers in pie and star charts.

9

-

Intersection of axes in bar charts.

16

/

Ends of blocks and the diagonal lines that separate blocks in a block chart.

20

*

Circles in pie and star charts.

click to expand
Figure 7.1: Formatting Characters Commonly Used in PROC CHART Output
  • formatting-character(s)

    • lists the characters to use for the specified positions. PROC CHART assigns characters in formatting-character(s) to position(s) , in the order that they are listed. For instance, the following option assigns the asterisk (*) to the second formatting character, the pound sign (#) to the seventh character, and does not alter the remaining characters:

       formchar(2,7)='*#' 
  • Interaction: The SAS system option FORMCHAR= specifies the default formatting characters. The system option defines the entire string of formatting characters. The FORMCHAR= option in a procedure can redefine selected characters.

  • Tip: You can use any character in formatting-characters , including hexadecimal characters. If you use hexadecimal characters, then you must put an x after the closing quotation mark. For instance the following option assigns the hexadecimal character 2D to the second formatting character, the hexadecimal character 7C to the seventh character, and does not alter the remaining characters:

     formchar(2,7)='2D7C'x 
  • See also: For information on which hexadecimal codes to use for which characters, consult the documentation for your hardware.

LPI= value

  • specifies the proportions of PIE and STAR charts. The value is determined by

    click to expand
  • For example, if you have a printer with 8 lines per inch and 12 columns per inch, then specify LPI=6.6667.

  • Default: 6

BLOCK Statement

Produces a block chart.

Featured in: Example 6 on page 208

BLOCK variable(s) </ option(s) >;

Required Arguments

variable(s)

  • specifies the variables for which PROC CHART produces a block chart, one chart for each variable.

Options

The options available on the BLOCK, HBAR, PIE, STAR, and VBAR statements are documented in Customizing All Types of Charts on page 189.

Statement Results

Because each block chart must fit on one output page, you may have to adjust the SAS system options LINESIZE= and PAGESIZE= if you have a large number of charted values for the BLOCK variable and for the variable specified in the GROUP= option.

Table 7.2 on page 185 shows the maximum number of charted values of BLOCK variables for selected LINESIZE= (LS=) specifications that can fit on a 66-line page.

Table 7.2: Maximum Number of Bars of BLOCK Variables

GROUP= Value

LS= 132

LS= 120

LS= 105

LS= 90

LS= 76

LS= 64

0,1

9

8

7

6

5

4

2

8

8

7

6

5

4

3

8

7

6

5

4

3

4

7

7

6

5

4

3

5,6

7

6

5

4

3

2

If the value of any GROUP= level is longer than three characters, then the maximum number of charted values for the BLOCK variable that can fit might be reduced by one. BLOCK level values truncate to 12 characters. If you exceed these limits, then PROC CHART produces a horizontal bar chart instead.

BY Statement

Produces a separate chart for each BY group.

Main discussion: BY on page 58

Featured in: Example 6 on page 208

BY <DESCENDING> variable-1

  • < <DESCENDING> variable-n >

  • <NOTSORTED>;

Required Arguments

variable

  • specifies the variable that the procedure uses to form BY groups. You can specify more than one variable. If you do not use the NOTSORTED option in the BY statement, then the observations in the data set must either be sorted by all the variables that you specify, or they must be indexed appropriately. Variables in a BY statement are called BY variables .

Options

DESCENDING

  • specifies that the observations are sorted in descending order by the variable that immediately follows the word DESCENDING in the BY statement.

NOTSORTED

  • specifies that observations are not necessarily sorted in alphabetic or numeric order. The observations are grouped in another way, for example, chronological order.

  • The requirement for ordering or indexing observations according to the values of BY variables is suspended for BY-group processing when you use the NOTSORTED option. In fact, the procedure does not use an index if you specify NOTSORTED. The procedure defines a BY group as a set of contiguous observations that have the same values for all BY variables. If observations with the same values for the BY variables are not contiguous, then the procedure treats each contiguous set as a separate BY group.

HBAR Statement

Produces a horizontal bar chart.

Tip: HBAR charts can print either the name or the label of the chart variable.

Featured in: Example 5 on page 207

HBAR variable(s) </ option(s) >;

Required Argument

variable(s)

  • specifies the variables for which PROC CHART produces a horizontal bar chart, one chart for each variable.

Options

The options available on the BLOCK, HBAR, PIE, STAR, and VBAR statements are documented in Customizing All Types of Charts on page 189.

Statement Results

Each chart occupies one or more output pages, depending on the number of bars; each bar occupies one line, by default.

By default, for horizontal bar charts of TYPE=FREQ, CFREQ, PCT, or CPCT, PROC CHART prints the following statistics: frequency, cumulative frequency, percentage, and cumulative percentage. If you use one or more of the statistics options, then PROC CHART prints only the statistics that you request, plus the frequency.

PIE Statement

Produces a pie chart.

PIE variable(s) </ option(s) >;

Required Argument

variable(s)

  • specifies the variables for which PROC CHART produces a pie chart, one chart for each variable.

Options

The options available on the BLOCK, HBAR, PIE, STAR, and VBAR statements are documented in Customizing All Types of Charts on page 189.

Statement Results

PROC CHART determines the number of slices for the pie in the same way that it determines the number of bars for vertical bar charts. Any slices of the pie accounting for less than three print positions are grouped together into an "OTHER" category.

The pie s size is determined only by the SAS system options LINESIZE= and PAGESIZE=. By default, the pie looks elliptical if your printer does not print 6 lines per inch and 10 columns per inch. To make a circular pie chart on a printer that does not print 6 lines and 10 columns per inch, use the LPI= option on the PROC CHART statement. See the description of LPI= on page 185 for the formula that gives you the proper LPI= value for your printer.

If you try to create a PIE chart for a variable with more than 50 levels, then PROC CHART produces a horizontal bar chart instead.

STAR Statement

Produces a star chart.

STAR variable(s) </ option(s) >;

Required Argument

variable(s)

  • specifies the variables for which PROC CHART produces a star chart, one chart for each variable.

Options

The options available on the BLOCK, HBAR, PIE, STAR, and VBAR statements are documented in Customizing All Types of Charts on page 189.

Statement Results

The number of points in the star is determined in the same way as the number of bars for vertical bar charts.

If all the data values are positive, then the center of the star represents zero and the outside circle represents the maximum value. If any data values are negative, then the center represents the minimum. See the description of the AXIS= option on page 191 for more information about how to specify maximum and minimum values. For information about how to specify the proportion of the chart, see the description of the LPI= option on page 185.

If you try to create a star chart for a variable with more than 24 levels, then PROC CHART produces a horizontal bar chart instead.

VBAR Statement

Produces a vertical bar chart.

Featured in: Example 1 on page 196, Example 2 on page 199, Example 3 on page 201, Example 4 on page 204

VBAR variable(s) </ option(s) >;

Required Argument

variable(s)

  • specifies the variables for which PROC CHART produces a vertical bar chart, one chart for each variable.

Options

The options available on the BLOCK, HBAR, PIE, STAR, and VBAR statements are documented in Customizing All Types of Charts on page 189.

Statement Results

PROC CHART prints one page per chart. Along the vertical axis, PROC CHART describes the chart frequency, the cumulative frequency, the chart percentage, the cumulative percentage, the sum, or the mean. At the bottom of each bar, PROC CHART prints a value according to the value of the TYPE= option, if specified. For character variables or discrete numeric variables, this value is the actual value represented by the bar. For continuous numeric variables, the value gives the midpoint of the interval represented by the bar.

PROC CHART can automatically scale the vertical axis, determine the bar width, and choose spacing between the bars. However, by using options, you can choose bar intervals and the number of bars, include missing values in the chart, produce side-by-side charts, and subdivide the bars. If the number of characters per line (LINESIZE=) is not sufficient to display all vertical bars, then PROC CHART produces a horizontal bar chart instead.

Customizing All Types of Charts

Many options in PROC CHART are valid in more than one statement. This section describes the options that you can use on the chart-producing statements.

To do this

Use this option

Specify that numeric variables are discrete

DISCRETE

Specify a frequency variable

FREQ=

Specify that missing values are valid levels

MISSING

Specify the variable for which values or means are displayed

SUMVAR=

Specify the statistic represented in the chart

TYPE=

Specify groupings

 
 

Group the bars in side-by-side charts

GROUP=

 

Specify that group percentages sum to 100

G100

 

Group the bars in side-by-side charts

GROUP=

 

Specify the number of bars for continuous variables

LEVELS=

 

Define ranges for continuous variables

MIDPOINTS=

 

Divide the bars into categories

SUBGROUP =

Compute statistics

 
 

Compute the cumulative frequency for each bar

CFREQ

 

Compute the cumulative percentage for each bar

CPERCENT

 

Compute the frequency for each bar

FREQ

 

Compute the mean of the observations for each bar

MEAN

 

Compute the percentage of total observations for each bar

PERCENT

 

Compute the total number of observations for each bar

SUM

Control output format

 
 

Print the bars in ascending order of size

ASCENDING

 

Specify the values for the response axis

AXIS=

 

Print the bars in descending order of size

DESCENDING

 

Specify extra space between groups of bars

GSPACE=

 

Suppress the default header line

NOHEADER

 

Allow no space between vertical bars

NOSPACE

 

Suppress the statistics

NOSTATS

 

Suppress the subgroup legend or symbol table

NOSYMBOL

 

Suppress the bars with zero frequency

NOZEROS

 

Draw reference lines

REF=

 

Specify the spaces between bars

SPACE=

 

Specify the symbols within bars or blocks

SYMBOL=

 

Specify the width of bars

WIDTH=

Options

ASCENDING

  • prints the bars and any associated statistics in ascending order of size within groups.

  • Alias: ASC

  • Restriction: Available only on the HBAR and VBAR statements

AXIS= value-expression

  • specifies the values for the response axis, where value-expression is a list of individual values, each separated by a space, or a range with a uniform interval for the values. For example, the following range specifies tick marks on a bar chart from 0 to 100 at intervals of 10:

     hbar x / axis=0 to 100 by 10; 
  • Restriction: Not available on the PIE statement

  • Restriction: Values must be uniformly spaced , even if you specify them individually.

  • Restriction: For frequency charts, values must be integers.

  • Interaction: For BLOCK charts, AXIS= sets the scale of the tallest block. To set the scale, PROC CHART uses the maximum value from the AXIS= list. If no value is greater than 0, then PROC CHART ignores the AXIS= option.

  • Interaction: For HBAR and VBAR charts, AXIS= determines tick marks on the response axis. If the AXIS= specification contains only one value, then the value determines the minimum tick mark if the value is less than 0, or determines the maximum tick mark if the value is greater than 0.

  • Interaction: For STAR charts, a single AXIS= value sets the minimum (the center of the chart) if the value is less than zero, or sets the maximum (the outside circle) if the value is greater than zero. If the AXIS= specification contains more than one value, then PROC CHART uses the minimum and maximum values from the list.

  • Interaction: If you use AXIS= and the BY statement, then PROC CHART produces uniform axes over BY groups.

  • CAUTION:

    • Values in value-expression override the range of the data. For example, if the data range is 1 to 10 and you specify a range of 3 to 5, then only the data in the range 3 to 5 appears on the chart. Values out of range produce a warning message in the SAS log.

CFREQ

  • prints the cumulative frequency.

  • Restriction: Available only on the HBAR statement

CPERCENT

  • prints the cumulative percentages.

  • Restriction: Available only on the HBAR statement

DESCENDING

  • prints the bars and any associated statistics in descending order of size within groups.

  • Alias: DESC

  • Restriction: Available only on the HBAR and VBAR statements

DISCRETE

  • specifies that a numeric chart variable is discrete rather than continuous. Without DISCRETE, PROC CHART assumes that all numeric variables are continuous and automatically chooses intervals for them unless you use MIDPOINTS= or LEVELS=.

FREQ

  • prints the frequency of each bar to the side of the chart.

  • Restriction: Available only on the HBAR statement

FREQ= variable

  • specifies a data set variable that represents a frequency count for each observation. Normally, each observation contributes a value of one to the frequency counts. With FREQ=, each observation contributes its value of the FREQ= value.

  • Restriction: If the FREQ= values are not integers, then PROC CHART truncates them.

  • Interaction: If you use SUMVAR=, then PROC CHART multiplies the sums by the FREQ= value.

GROUP= variable

  • produces side-by-side charts, with each chart representing the observations that have a common value for the GROUP= variable. The GROUP= variable can be character or numeric and is assumed to be discrete. For example, the following statement produces a frequency bar chart for men and women in each department:

     vbar gender / group=dept; 

    Missing values for a GROUP= variable are treated as valid levels.

  • Restriction: Available only on the BLOCK, HBAR, and VBAR statements

  • Featured in: Example 4 on page 204, Example 5 on page 207, Example 6 on page 208

GSPACE= n

  • specifies the amount of extra space between groups of bars. Use GSPACE=0 to leave no extra space between adjacent groups of bars.

  • Restriction: Available only on the HBAR and VBAR statements

  • Interaction: PROC CHART ignores GSPACE= if you omit GROUP=

G100

  • specifies that the sum of percentages for each group equals 100. By default, PROC CHART uses 100 percent as the total sum. For example, if you produce a bar chart that separates males and females into three age categories, then the six bars, by default, add to 100 percent; however, with G100, the three bars for females add to 100 percent, and the three bars for males add to 100 percent.

  • Restriction: Available only on the BLOCK, HBAR, and VBAR statements

  • Interaction: PROC CHART ignores G100 if you omit GROUP=.

LEVELS= number-of-midpoints

  • specifies the number of bars that represent each chart variable when the variables are continuous.

MEAN

  • prints the mean of the observations represented by each bar.

  • Restriction: Available only on the HBAR statement and only when you use SUMVAR= and TYPE=

  • Restriction: Not available when TYPE=CFREQ, CPERCENT, FREQ, or PERCENT

MIDPOINTS= midpoint-specification OLD

  • defines the range of values that each bar, block, or section represents by specifying the range midpoints.

    • The value for MIDPOINTS= is one of the following:

  • midpoint-specification

    • specifies midpoints, either individually, or across a range at a uniform interval. For example, the following statement produces a chart with five bars; the first bar represents the range of values of X with a midpoint of 10, the second bar represents the range with a midpoint of 20, and so on:

       vbar x / midpoints=10 20 30 40 50; 
      • Here is an example of a midpoint specification for a character variable:

         vbar x / midpoints='JAN' 'FEB' 'MAR'; 
      • Here is an example of specifying midpoints across a range at a uniform interval:

         vbar x / midpoints=10 to 100 by 5; 
  • OLD

    • specifies an algorithm that PROC CHART used in previous versions of SAS to choose midpoints for continuous variables. The old algorithm was based on the work of Nelder (1976). The current algorithm that PROC CHART uses if you omit OLD is based on the work of Terrell and Scott (1985).

  • Default: Without MIDPOINTS=, PROC CHART displays the values in the SAS System's normal sorted order.

  • Restriction: When the VBAR variables are numeric, the midpoints must be given in ascending order.

MISSING

  • specifies that missing values are valid levels for the chart variable.

NOHEADER

  • suppresses the default header line printed at the top of a chart.

  • Alias: NOHEADING

  • Restriction: Available only on the BLOCK, PIE, and STAR statements

  • Featured in: Example 6 on page 208

NOSTATS

  • suppresses the statistics on a horizontal bar chart.

  • Alias: NOSTAT

  • Restriction: Available only on the HBAR statement

NOSYMBOL

  • suppresses printing of the subgroup symbol or legend table.

  • Alias: NOLEGEND

  • Restriction: Available only on the BLOCK, HBAR, and VBAR statements

  • Interaction: PROC CHART ignores NOSYMBOL if you omit SUBGROUP=.

NOZEROS

  • suppresses any bar with zero frequency.

  • Restriction: Available only on the HBAR and VBAR statements

PERCENT

  • prints the percentages of observations having a given value for the chart variable.

  • Restriction: Available only on the HBAR statement

REF= value(s)

  • draws reference lines on the response axis at the specified positions.

  • Restriction: Available only on the HBAR and VBAR statements

  • Tip: The REF= values should correspond to values of the TYPE= statistic.

  • Featured in: Example 4 on page 204

SPACE= n

  • specifies the amount of space between individual bars.

  • Restriction: Available only on the HBAR and VBAR statements

  • Tip: Use SPACE=0 to leave no space between adjacent bars.

  • Tip: Use the GSPACE= option to specify the amount of space between the bars within each group.

SUBGROUP= variable

  • subdivides each bar or block into characters that show the contribution of the values of variable to that bar or block. PROC CHART uses the first character of each value to fill in the portion of the bar or block that corresponds to that value, unless more than one value begins with the same first character. In that case, PROC CHART uses the letters A, B, C, and so on to fill in the bars or blocks. If the variable is formatted, then PROC CHART uses the first character of the formatted value.

    The characters used in the chart and the values that they represent are given in a legend at the bottom of the chart. The subgroup symbols are ordered A through Z and 0 through 9 with the characters in ascending order.

    PROC CHART calculates the height of a bar or block for each subgroup individually and then rounds the percentage of the total bar up or down. So the total height of the bar may be higher or lower than the same bar without the SUBGROUP= option.

  • Restriction: Available only on the BLOCK, HBAR, and VBAR statements

  • Interaction: If you use both TYPE=MEAN and SUBGROUP=, then PROC CHART first calculates the mean for each variable that is listed in the SUMVAR= option, then subdivides the bar into the percentages that each subgroup contributes.

  • Featured in: Example 3 on page 201

SUM

  • prints the total number of observations that each bar represents.

  • Restriction: Available only on the HBAR statement and only when you use both SUMVAR= and TYPE=

  • Restriction: Not available when TYPE=CFREQ, CPERCENT, FREQ, or PERCENT

SUMVAR= variable

  • specifies the variable for which either values or means (depending on the value of TYPE=) PROC CHART displays in the chart.

  • Interaction: If you use SUMVAR= and you use TYPE= with a value other than MEAN or SUM, then TYPE=SUM overrides the specified TYPE= value.

  • Tip: Both HBAR and VBAR charts can print labels for SUMVAR= variables if you use a LABEL statement.

  • Featured in: Example 3 on page 201, Example 4 on page 204, Example 5 on page 207 , Example 6 on page 208

SYMBOL= character(s)

  • specifies the character or characters that PROC CHART uses in the bars or blocks of the chart when you do not use the SUBGROUP= option.

  • Default: asterisk (*)

  • Restriction: Available only on the BLOCK, HBAR, and VBAR statements

  • Interaction: If the SAS system option OVP is in effect and if your printing device supports overprinting, then you can specify up to three characters to produce overprinted charts.

  • Featured in: Example 6 on page 208

TYPE= statistic

  • specifies what the bars or sections in the chart represent. The statistic is one of the following:

  • CFREQ

    • specifies that each bar, block, or section represent the cumulative frequency.

  • CPERCENT

    • specifies that each bar, block, or section represent the cumulative percentage.

    • Alias: CPCT

  • FREQ

    • specifies that each bar, block, or section represent the frequency with which a value or range occurs for the chart variable in the data.

  • MEAN

    • specifies that each bar, block, or section represent the mean of the SUMVAR= variable across all observations that belong to that bar, block, or section.

    • Interaction: With TYPE=MEAN, you can only compute MEAN and FREQ statistics.

    • Featured in: Example 4 on page 204

  • PERCENT

    • specifies that each bar, block, or section represent the percentage of observations that have a given value or that fall into a given range of the chart variable.

    • Alias: PCT

    • Featured in: Example 2 on page 199

  • SUM

    • specifies that each bar, block, or section represent the sum of the SUMVAR= variable for the observations that correspond to each bar, block, or section.

    • Default: FREQ (unless you use SUMVAR=, which causes a default of SUM)

    • Interaction: With TYPE=SUM, you can only compute SUM and FREQ statistics.

WIDTH= n

  • specifies the width of the bars on bar charts.

  • Restriction: Available only on the HBAR and VBAR statements




Base SAS 9.1.3 Procedures Guide (Vol. 1)
Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4
ISBN: 1590472047
EAN: 2147483647
Year: 2004
Pages: 260

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net