Examples: CHART Procedure


Example 1: Producing a Simple Frequency Count

Procedure features:

  • VBAR statement

This example produces a vertical bar chart that shows a frequency count for the values of the chart variable.

Program

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.

 options nodate pageno=1 linesize=80 pagesize=60; 

Create the SHIRTS data set. SHIRTS contains the sizes of a particular shirt that is sold during a week at a clothing store, with one observation for each shirt that is sold.

 data shirts;     input Size $ @@;     datalines;  medium    large  large     large  large     medium  medium    small  small     medium  medium    large  small     medium  large     large  large     small  medium    medium  medium    medium  medium    large  small     small  ; 

Create a vertical bar chart with frequency counts. The VBAR statement produces a vertical bar chart for the frequency counts of the Size values.

 proc chart data=shirts;     vbar size; 

Specify the title.

 title 'Number of Each Shirt Size Sold';  run; 

Output

The frequency chart shows the store s sales of the shirt for the week: 9 large shirts, 11 medium shirts, and 6 small shirts.

 Number of Each Shirt Size Sold                  1  Frequency  11 +                   *****                        *****                        *****                        *****  10 +                   *****                        *****                        *****                        *****   9 +       *****       *****            *****       *****            *****       *****            *****       *****   8 +       *****       *****            *****       *****            *****       *****            *****       *****   7 +       *****       *****            *****       *****            *****       *****            *****       *****   6 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****   5 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****   4 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****   3 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****   2 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****   1 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****     --------------------------------------------            large      medium       small                         Size 

Example 2: Producing a Percentage Bar Chart

Procedure features:

  • VBAR statement option:

    • TYPE=

Data set: SHIRTS on page 197

This example produces a vertical bar chart. The chart statistic is the percentage for each category of the total number of shirts sold.

Program

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.

 options nodate pageno=1 linesize=80 pagesize=60; 

Create a vertical bar chart with percentages. The VBAR statement produces a vertical bar chart. TYPE= specifies percentage as the chart statistic for the variable Size.

 proc chart data=shirts;     vbar size / type=percent; 

Specify the title.

 title 'Percentage of Total Sales for Each Shirt Size';  run; 

Output

The chart shows the percentage of total sales for each shirt size. Of all the shirts sold, about 42.3 percent were medium, 34.6 were large, and 23.1 were small.

 Percentage of Total Sales for Each Shirt Size              1  Percentage                        *****                        *****  40 +                   *****                        *****                        *****                        *****                        *****  35 +       *****       *****            *****       *****            *****       *****            *****       *****            *****       *****  30 +       *****       *****            *****       *****            *****       *****            *****       *****            *****       *****  25 +       *****       *****            *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****  20 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****  15 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****  10 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****   5 +       *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****            *****       *****       *****     --------------------------------------------            large      medium       small                         Size 

Example 3: Subdividing the Bars into Categories

Procedure features:

  • VBAR statement options:

    • SUBGROUP =

    • SUMVAR=

  • This example

  • produces a vertical bar chart for categories of one variable with bar lengths that represent the values of another variable.

  • subdivides each bar into categories based on the values of a third variable.

Program

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.

 options nodate pageno=1 linesize=80 pagesize=60; 

Create the PIESALES data set. PIESALES contains the number of each flavor of pie that is sold for two years at three bakeries that are owned by the same company. One bakery is on Samford Avenue, one on Oak Street, and one on Clyde Drive.

 data piesales;     input Bakery $ Flavor $ Year Pies_Sold;     datalines;  Samford  apple      1995  234  Samford  apple      1996  288  Samford  blueberry  1995  103  Samford  blueberry  1996  143  Samford  cherry     1995  173  Samford  cherry     1996  195  Samford  rhubarb    1995   26  Samford  rhubarb    1996   28  Oak      apple      1995  319  Oak      apple      1996  371  Oak      blueberry  1995  174  Oak      blueberry  1996  206  Oak      cherry     1995  246  Oak      cherry     1996  311  Oak      rhubarb    1995   51  Oak      rhubarb    1996   56  Clyde    apple      1995  313  Clyde    apple      1996  415  Clyde    blueberry  1995  177  Clyde    blueberry  1996  201  Clyde    cherry     1995  250  Clyde    cherry     1996  328  Clyde    rhubarb    1995   60  Clyde    rhubarb    1996   59  ; 

Create a vertical bar chart with the bars that are subdivided into categories. The VBAR statement produces a vertical bar chart with one bar for each pie flavor. SUBGROUP= divides each bar into sales for each bakery.

 proc chart data=piesales;     vbar flavor / subgroup=bakery 

Specify the bar length variable. SUMVAR= specifies Pies_Sold as the variable whose values are represented by the lengths of the bars.

 sumvar=pies_sold; 

Specify the title.

 title 'Pie Sales by Flavor Subdivided by Bakery Location';  run; 

Output

The bar that represents the sales of apple pies, for example, shows 1,940 total pies across both years and all three bakeries. The symbol for the Samford Avenue bakery represents the 522 pies at the top, the symbol for the Oak Street bakery represents the 690 pies in the middle, and the symbol for the Clyde Drive bakery represents the 728 pies at the bottom of the bar for apple pies. By default, the labels along the horizontal axis are truncated to eight characters .

 Pie Sales by Flavor Subdivided by Bakery Location              1  Pies_Sold Sum              SSSSS              SSSSS              SSSSS  1800 +       SSSSS              SSSSS              SSSSS              SSSSS  1600 +       SSSSS              SSSSS              SSSSS                   SSSSS              OOOOO                   SSSSS  1400 +       OOOOO                   SSSSS              OOOOO                   SSSSS              OOOOO                   SSSSS              OOOOO                   SSSSS  1200 +       OOOOO                   SSSSS              OOOOO                   OOOOO              OOOOO                   OOOOO              OOOOO       SSSSS       OOOOO  1000 +       OOOOO       SSSSS       OOOOO              OOOOO       SSSSS       OOOOO              OOOOO       SSSSS       OOOOO              OOOOO       SSSSS       OOOOO   800 +       OOOOO       OOOOO       OOOOO              CCCCC       OOOOO       OOOOO              CCCCC       OOOOO       OOOOO              CCCCC       OOOOO       OOOOO   600 +       CCCCC       OOOOO       CCCCC              CCCCC       OOOOO       CCCCC              CCCCC       OOOOO       CCCCC              CCCCC       OOOOO       CCCCC   400 +       CCCCC       CCCCC       CCCCC              CCCCC       CCCCC       CCCCC              CCCCC       CCCCC       CCCCC              CCCCC       CCCCC       CCCCC       SSSSS   200 +       CCCCC       CCCCC       CCCCC       OOOOO              CCCCC       CCCCC       CCCCC       OOOOO              CCCCC       CCCCC       CCCCC       CCCCC              CCCCC       CCCCC       CCCCC       CCCCC       --------------------------------------------------------              apple     blueberr     cherry      rhubarb                                Flavor       Symbol Bakery      Symbol Bakery      Symbol Bakery          C   Clyde          O   Oak            S   Samford 

Example 4: Producing Side-by-Side Bar Charts

Procedure features:

  • VBAR statement options:

    • GROUP =

    • REF=

    • SUMVAR=

    • TYPE=

Data set: PIESALES Program on page 201

  • This example

  • charts the mean values of a variable for the categories of another variable

  • creates side-by-side bar charts for the categories of a third variable

  • draws reference lines across the charts.

Program

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.

 options nodate pageno=1 linesize=80 pagesize=60; 

Create a side-by-side vertical bar chart. The VBAR statement produces a side-by-side vertical bar chart to compare the sales across values of Bakery, specified by GROUP=. Each Bakery group contains a bar for each Flavor value.

 proc chart data=piesales;     vbar flavor / group=bakery 

Create reference lines. REF= draws reference lines to mark pie sales at 100, 200, and 300.

 ref=100 200 300 

Specify the bar length variable. SUMVAR= specifies Pies_Sold as the variable that is represented by the lengths of the bars.

 sumvar=pies_sold 

Specify the statistical variable. TYPE= averages the sales for 1995 and 1996 for each combination of bakery and flavor.

 type=mean; 

Specify the titles.

 title 'Mean Yearly Pie Sales Grouped by Flavor';     title2 'within Bakery Location';  run; 

Output

The side-by-side bar charts compare the sales of apple pies, for example, across bakeries. The mean for the Clyde Drive bakery is 364, the mean for the Oak Street bakery is 345, and the mean for the Samford Avenue bakery is 261.

 Mean Yearly Pie Sales Grouped by Flavor                   1                              within Bakery Location  Pies_Sold Mean        ***  350 +  ***                   ***        ***                   ***        ***                   ***        ***                   ***        ***                   ***  300 +--***-------------------***----------------------------------------------       ***       ***         ***        ***       ***         ***       ***        ***       ***         ***       ***        ***       ***         ***       ***         ***  250 +  ***       ***         ***       ***         ***        ***       ***         ***       ***         ***        ***       ***         ***       ***         ***        ***       ***         ***       ***         ***        ***       ***         ***       ***         ***  200 +--***-------***---------***-------***---------***------------------------       ***  ***  ***         ***  ***  ***         ***        ***  ***  ***         ***  ***  ***         ***       ***        ***  ***  ***         ***  ***  ***         ***       ***        ***  ***  ***         ***  ***  ***         ***       ***  150 +  ***  ***  ***         ***  ***  ***         ***       ***        ***  ***  ***         ***  ***  ***         ***       ***        ***  ***  ***         ***  ***  ***         ***       ***        ***  ***  ***         ***  ***  ***         ***  ***  ***        ***  ***  ***         ***  ***  ***         ***  ***  ***  100 +--***--***--***---------***--***--***---------***--***--***--------------       ***  ***  ***         ***  ***  ***         ***  ***  ***        ***  ***  ***         ***  ***  ***         ***  ***  ***        ***  ***  ***         ***  ***  ***         ***  ***  ***        ***  ***  ***  ***    ***  ***  ***         ***  ***  ***   50 +  ***  ***  ***  ***    ***  ***  ***  ***    ***  ***  ***        ***  ***  ***  ***    ***  ***  ***  ***    ***  ***  ***        ***  ***  ***  ***    ***  ***  ***  ***    ***  ***  ***  ***        ***  ***  ***  ***    ***  ***  ***  ***    ***  ***  ***  ***        ***  ***  ***  ***    ***  ***  ***  ***    ***  ***  ***  ***      --------------------------------------------------------------------------         a    b    c    r      a    b    c    r      a    b    c    r    Flavor          p    l    h    h      p    l    h    h      p    l    h    h          p    u    e    u      p    u    e    u      p    u    e    u          l    e    r    b      l    e    r    b      l    e    r    b          e    b    r    a      e    b    r    a      e    b    r    a               e    y    r           e    y    r           e    y    r               r         b           r         b           r         b               r                     r                     r         ----- Clyde ----    ------ Oak -----    ---- Samford ---   Bakery 

Example 5: Producing a Horizontal Bar Chart for a Subset of the Data

Procedure features:

  • HBAR statement options:

    • GROUP=

    • SUMVAR=

Other features:

  • WHERE= data set option

Data set: PIESALES Program on page 201

  • This example

  • produces horizontal bar charts only for observations with a common value

  • charts the values of a variable for the categories of another variable

  • creates side-by-side bar charts for the categories of a third variable.

Program

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.

 options nodate pageno=1 linesize=80 pagesize=60; 

Specify the variable value limitation for the horizontal bar chart. WHERE= limits the chart to only the 1995 sales totals.

 proc chart data=piesales(where=(year=1995)); 

Create a side-by-side horizontal bar chart. The HBAR statement produces a side-by-side horizontal bar chart to compare sales across values of Flavor, specified by GROUP=. Each Flavor group contains a bar for each Bakery value.

 hbar bakery / group=flavor 

Specify the bar length variable. SUMVAR= specifies Pies_Sold as the variable whose values are represented by the lengths of the bars.

 sumvar=pies_sold; 

Specify the title.

 title '1995 Pie Sales for Each Bakery According to Flavor';  run; 

Output

 1995 Pie Sales for Each Bakery According to Flavor                1  Flavor     Bakery                                                     Pies_Sold                                                                              Sum                         apple      Clyde     ******************************************       313.0000             Oak       *******************************************      319.0000             Samford   *******************************                  234.0000                         blueberr   Clyde     ************************                         177.0000             Oak       ***********************                          174.0000             Samford   **************                                   103.0000                         cherry     Clyde     *********************************                250.0000             Oak       *********************************                246.0000             Samford   ***********************                          173.0000                         rhubarb    Clyde     ********                                          60.0000             Oak       *******                                           51.0000             Samford   ***                                               26.0000                                              ----+---+---+---+---+---+---+---+---+---+---                          30  60  90 120 150 180 210 240 270 300                                       Pies_Sold Sum 

Example 6: Producing Block Charts for BY Groups

Procedure features:

  • BLOCK statement options:

    • GROUP=

    • NOHEADER=

    • SUMVAR=

    • SYMBOL=

  • BY statement

Other features:

  • PROC SORT

  • SAS system options:

    • NOBYLINE

    • OVP

  • TITLE statement:

    • # BYVAL specification

Data set: PIESALES Program on page 201

  • This example

  • sorts the data set

  • produces a block chart for each BY group

  • organizes the blocks into a three-dimensional chart

  • prints BY group-specific titles.

Program

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.

 options nodate pageno=1 linesize=80 pagesize=60; 

Sort the input data set PIESALES. PROC SORT sorts PIESALES by year. Sorting is required to produce a separate chart for each year.

 proc sort data=piesales out=sorted_piesales;     by year;  run; 

Suppress BY lines and allow overprinted characters in the block charts. NOBYLINE suppresses the usual BY lines in the output. OVP allows overprinted characters in the charts.

 options nobyline ovp; 

Specify the BY group for multiple block charts. The BY statement produces one chart for 1995 sales and one for 1996 sales.

 proc chart data=sorted_piesales;     by year; 

Create a block chart. The BLOCK statement produces a block chart for each year. Each chart contains a grid (Bakery values along the bottom, Flavor values along the side) of cells that contain the blocks.

 block bakery / group=flavor 

Specify the bar length variable. SUMVAR= specifies Pies_Sold as the variable whose values are represented by the lengths of the blocks.

 sumvar=pies_sold 

Suppress the default header line. NOHEADER suppresses the default header line.

 noheader 

Specify the block symbols. SYMBOL= specifies the symbols in the blocks.

 symbol='OX'; 

Specify the titles. The #BYVAL specification inserts the year into the second line of the title.

 title 'Pie Sales for Each Bakery and Flavor';     title2 '#byval(year)';  run; 

Reset the printing of the default BY line. The SAS system option BYLINE resets the printing of the default BY line.

 options byline; 

Output

click to expand
click to expand



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