GCHART Procedure

Example 3: Specifying the Sum Statistic in Bar Charts

Features:

HBAR statement option SUMVAR= and VBAR3D statement option SUMVAR=

Other features:

FORMAT statement, GOPTIONS statement option BORDER, and RUN-group processing

Sample library member: GCHBRSUM
This example produces two bar charts that show the total sales for three sites by charting the values of the character variable SITE and calculating the sum of the variable SALES for each site.
In the first horizontal bar chart shown, the summary statistics are printed by default to the right of the bars and display the formatted values of SALES.
The output also shows the frame that is drawn by default around the axis area.
The second bar chart is a three-dimensional vertical bar chart, shown in the following output. Vertical bar charts do not generate a table of statistics and by default do not print any chart statistics.
GCHBRSUM(a)-Horizontal Bar chart with SUM statistic
GCHBRSUM(b)-Vertical bar chart with SUM statistic

Program

goptions reset=all border;
data totals;
length dept $ 7 site $ 8;
input dept site quarter sales;
datalines;
Parts Sydney 1 7043.97
Parts Atlanta 1 8225.26
Parts Paris 1 5543.97
Tools Sydney 4 1775.74
Tools Atlanta 4 3424.19
Tools Paris 4 6914.25
;
title1 "Total Sales"; 
proc gchart data=totals;
format sales dollar8.;
hbar site / sumvar=sales;
run;
  vbar3d site / sumvar=sales;
run;
quit;

Program Description

Set the graphics environment. The BORDER option in the GOPTIONS statement draws a black border around the graph.
goptions reset=all border;
Create data set TOTALS. TOTALS contains quarterly sales data for three manufacturing sites for one year. Sales figures are broken down by department.
data totals;
length dept $ 7 site $ 8;
input dept site quarter sales;
datalines;
Parts Sydney 1 7043.97
Parts Atlanta 1 8225.26
Parts Paris 1 5543.97
Tools Sydney 4 1775.74
Tools Atlanta 4 3424.19
Tools Paris 4 6914.25
;
Define title for the charts.
title1 "Total Sales"; 
Produce the horizontal bar chart. The HBAR statement produces a two-dimensional bar chart. SUMVAR= calculates the sum of SALES for each value of the chart variable SITE. The default statistic for SUMVAR= is SUM. The variable SALES is assigned a dollar format. The embedded RUN statement is required to end this first RUN-Group and honor the action statement and other SAS statements. It signals that the procedure is to remain active.
proc gchart data=totals;
format sales dollar8.;
hbar site / sumvar=sales;
run;
Produce the vertical bar chart. Because the procedure supports RUN-group processing, you do not have to repeat the PROC GCHART statement to generate the second chart. The VBAR3D statement produces a three-dimensional vertical bar chart.
  vbar3d site / sumvar=sales;
run;
quit;