Producing Charts to Summarize Variables |
Types of Frequency Charts |
By default, PROC CHART creates a frequency chart in which each bar, section, or block in the chart represents a range of values. By default, PROC CHART selects ranges based on the values of the chart variable. At the center of each range is a midpoint. A midpoint does not always correspond to an actual value of the chart variable. The size of each bar, block, or section represents the number of observations that fall in that range.
PROC CHART makes several different types of charts:
display the magnitude of data with the length or height of bars.
display the relative magnitude of data with blocks of varying size.
display data as wedge-shaped sections of a circle that represent the relative contribution of each section to the whole circle.
display data as bars that radiate from a center point, like spokes in a wheel.
Creating Vertical Bar Charts |
A vertical bar chart emphasizes individual ranges. The horizontal, or midpoint, axis shows the values of the variable divided into ranges. By default, the vertical axis shows the frequency of values for a given range. The differences in bar heights enable you to quickly determine which ranges contain many observations and which contain few observations.
The VBAR statement in a PROC CHART step produces vertical bar charts. If you use the VBAR statement without any options, then PROC CHART automatically does the following:
For continuous numeric data, PROC CHART determines the number of bars and the midpoint for each bar from the minimum and maximum value of the chart variable. For character variables or discrete numeric variables, PROC CHART creates a bar for each value of the chart variable. However, you can change how PROC CHART determines the axes by using options.Note: If the number of characters per line (LINESIZE=) is not sufficient to display vertical bars, then PROC CHART automatically produces a horizontal bar chart.
The following program uses the VBAR statement to create a vertical bar chart of frequencies for the numeric variable ExamGrade1:
options pagesize=40 linesize=80 pageno=1 nodate; proc chart data=grades; vbar ExamGrade1; title 'Grades for First Chemistry Exam'; run;
The following output shows the bar chart:
Using a Vertical Bar Chart to Show Frequencies
Grades for First Chemistry Exam 1 Frequency 14 + ***** | ***** 13 + ***** | ***** 12 + ***** | ***** 11 + ***** ***** | ***** ***** 10 + ***** ***** ***** | ***** ***** ***** 9 + ***** ***** ***** | ***** ***** ***** 8 + ***** ***** ***** | ***** ***** ***** 7 + ***** ***** ***** | ***** ***** ***** 6 + ***** ***** ***** ***** | ***** ***** ***** ***** 5 + ***** ***** ***** ***** ***** | ***** ***** ***** ***** ***** 4 + ***** ***** ***** ***** ***** | ***** ***** ***** ***** ***** 3 + ***** ***** ***** ***** ***** ***** | ***** ***** ***** ***** ***** ***** 2 + ***** ***** ***** ***** ***** ***** | ***** ***** ***** ***** ***** ***** 1 + ***** ***** ***** ***** ***** ***** ***** | ***** ***** ***** ***** ***** ***** ***** ---------------------------------------------------------------------------- 40 50 60 70 80 90 100 ExamGrade1 MidpointThe midpoint axis for the above chart ranges from 40 to 100 and is incremented in intervals of 10. The following table shows the values and frequency of each bar:
Range | Midpoint | Frequency |
---|---|---|
35 to 44 | 40 | 3 |
45 to 54 | 50 | 6 |
55 to 64 | 60 | 14 |
65 to 74 | 70 | 5 |
75 to 84 | 80 | 11 |
85 to 94 | 90 | 10 |
95 to 104 | 10 | 1 |
Note: Because PROC CHART selects the size of the ranges and the location of their midpoints based on all values of the numeric variable, the highest and lowest ranges can extend beyond the values in the data. In this example the lowest grade is 39 while the lowest range extends from 35 to 44. Similarly, the highest grade is 98 while the highest range extends from 95 to 104.
Creating a Horizontal Bar Chart |
A horizontal bar chart has essentially the same characteristics as a vertical bar chart. Both charts emphasize individual ranges. However, a horizontal bar chart rotates the bars so that the horizontal axis shows frequency and the vertical axis shows the values of the chart variable. To the right of the horizontal bars, PROC CHART displays a table of statistics that summarizes the data.
The HBAR statement in a PROC CHART step produces horizontal bar charts. By default, the table of statistics includes frequency, cumulative frequency, percentage, and cumulative percentage. You can request specific statistics so that the table contains only these statistics and the frequency.
The default horizontal bar chart uses less space than charts of other shapes. PROC CHART takes advantage of the small size of horizontal bar charts and displays statistics to the right of the chart. The statistics include
is the number of observations in all ranges up to and including a given range. The cumulative frequency for the last range is equal to the number of observations in the data set.
is the percentage of observations in all ranges up to and including a given range. The cumulative percentage for the last range is always 100.
Various options enable you to control the statistics that appear in the table. You can select the statistics by using the following options: FREQ, CFREQ, PERCENT, and CPERCENT. To suppress the table of statistics, use the NOSTAT option.
The following program uses the HBAR statement to create a horizontal bar chart of the frequency for the variable ExamGrade1:
options pagesize=40 linesize=80 pageno=1 nodate; proc chart data=grades; hbar Examgrade1; title 'Grades for First Chemistry Exam'; run;
The following output shows the bar chart:
Using a Horizontal Bar Chart to Show Frequencies
Grades for First Chemistry Exam 1 ExamGrade1 Cum. Cum. Midpoint Freq Freq Percent Percent | 40 |****** 3 3 6.00 6.00 | 50 |************ 6 9 12.00 18.00 | 60 |**************************** 14 23 28.00 46.00 | 70 |********** 5 28 10.00 56.00 | 80 |********************** 11 39 22.00 78.00 | 90 |******************** 10 49 20.00 98.00 | 100 |** 1 50 2.00 100.00 | ----+---+---+---+---+---+---+ 2 4 6 8 10 12 14 FrequencyThe cumulative percent shows that the median grade for the exam (the grade that 50% of observations lie above and 50% below) lies within the midpoint of 70.
The next example produces the same horizontal bar chart as above, but the program uses the NOSTAT option to eliminate the table of statistics.
options pagesize=40 linesize=80 pageno=1 nodate; proc chart data=grades; hbar Examgrade1 / nostat; title 'Grades for First Chemistry Exam'; run;
The following output shows the bar chart:
Removing Statistics from a Horizontal Bar Chart
Grades for First Chemistry Exam 1 ExamGrade1 Midpoint | 40 |************ | 50 |************************ | 60 |******************************************************** | 70 |******************** | 80 |******************************************** | 90 |**************************************** | 100 |**** | ----+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Frequency
Creating Block Charts |
A block chart displays the relative magnitude of data by using blocks of varying height. Each block in a square represents a category of data. A block chart is similar to a vertical bar chart. It uses a more sophisticated presentation of the data to emphasize the individual ranges. However, a block chart is less precise than a bar chart because the maximum height of a block is 10 lines.
The BLOCK statement in a PROC CHART step produces a block chart. You can also use the BLOCK statement to create three-dimensional frequency charts. For an example, see Creating a Three-Dimensional Chart. If you create block charts with a large number of charted values, then you might have to adjust the SAS system options LINESIZE= and PAGESIZE= so that the block chart fits on one page.
Note: If the line size or page size is not sufficient to display all the bars, then PROC CHART automatically produces a horizontal bar chart.
The following program uses the BLOCK statement to create a block frequency chart for the numeric variable ExamGrade1:
options linesize=120 pagesize=40 pageno=1 nodate; proc chart data=grades; block Examgrade1; title 'Grades for First Chemistry Exam'; run;
The OPTIONS statement increases the line size to 120.
The following output shows the block chart:
Using a Block Chart to Show Frequencies
Grades for First Chemistry Exam 1 Frequency of ExamGrade1 ___ /_ /|3 |**| | ___ |**| | /_ /| ___ |**| | |**| | /_ /| |**| | |**| | |**| | ___ |**| | ___ |**| | |**| | ----------------/_ /|--------|**| |---------/_ /|--------|**| |--------|**| |--------------------- / ___ / |**| | / |**| | / |**| | / |**| | / |**| | / / / /_ /| / |**| | / |**| | / |**| | / |**| | / |**| | / ___ / / |**| | / |**| | / |**| | / |**| | / |**| | / |**| | / /_ /| / / |**|/ / |**|/ / |**|/ / |**|/ / |**|/ / |**|/ / |**|/ / / / / / / / / / / 3 / 6 / 142 / 5 / 11 / 10 / 1 / /-------------/-------------/-------------/-------------/-------------/-------------/-------------/ 40 50 60 70 80 90 1001 ExamGrade1 MidpointThe chart shows the effects of using the BLOCK statement.
Creating Pie Charts |
A pie chart emphasizes the relative contribution of parts (a range of values) to the whole. Graphing the distribution of grades as a pie chart shows you the size of each range relative to the others just as the vertical bar chart does. However, the pie chart also enables you to visually compare the number of grades in a range to the total number of grades.
The PIE statement in a PROC CHART step produces a pie chart. PROC CHART determines the number of sections for the pie chart the same way it determines the number of bars for a vertical chart, with one exception: if any slices of the pie account for fewer than three print positions, then PROC CHART groups them into a category called "Other."
PROC CHART displays the values of the midpoints around the perimeter of the pie chart. Inside each section of the chart, PROC CHART displays the number of observations in the range and the percentage of observations that the number represents.
The SAS system options LINESIZE= and PAGESIZE= determine the size of the pie. If your printer does not print 6 lines per inch and 10 columns per inch, then the pie looks elliptical. To make a circular pie chart, you must use the LPI= option in the PROC CHART statement. For more information, see the CHART procedure in the Base SAS Procedures Guide.
The following program uses the PIE statement to create a pie chart of frequencies for the numeric variable ExamGrade1:
options pagesize=40 linesize=80 pageno=1 nodate; proc chart data=grades; pie ExamGrade1; title 'Grades for First Chemistry Exam'; run;
The following output shows the pie chart:
Using a Pie Chart to Show Frequencies
Grades for First Chemistry Exam 1 Frequency of ExamGrade1 60 ************* **** **** *** . *** ** . ** ** . ** 50 * . * * 14 . * ** 28.00% . 6 ** * . 12.00% * * . . * ** . . . . ** * . .. . .. . * 40 * .. . . . .. 3 * * . . .. . .. 6.00% * * 5 . + . . .. . .. .1.. . .* 70 * 10.00% .. . .. . ..2.00% * Other * .. . .. * * . .. . * ** . . . . ** * . . 10 * * . 20.00% * ** 11 . ** * 22.00% . * * . * ** . ** 90 ** . ** *** . *** 80 **** . **** *************In this pie chart the Other section represents the one grade in the range with a midpoint of 100. The size of a section corresponds to the number of observations that fall in its range.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.