CHART Procedure

Example 6: Producing Block Charts for BY Groups

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

Details

This example does the following:
  • 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

proc sort data=piesales out=sorted_piesales;
   by year;
run;
options nobyline;
proc chart data=sorted_piesales;
   by year;
   block bakery / group=flavor
                  sumvar=pies_sold
                  noheader
                  symbol='OX';
   title  'Pie Sales for Each Bakery and Flavor';
   title2 '#byval(year)';
run;
options byline;

Program Description

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.
options nobyline;
Specify the BY group for multiple block charts. The BY statement produces one chart for 2005 sales and one for 2006 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: HTML

2005 Pie Sales for Each Bakery and Flavor
2006 Pie Sales for Each Bakery and Flavor