Sample 25342: Generating HBAR, VBAR, BLOCK, PIE, and STAR charts with PROC CHART
This sample uses PROC CHART to generate HBAR, VBAR, BLOCK, PIE, and STAR charts.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample is from the SAS Sample Library. For additional information, refer to SAS Help and Online Documentation.
/****************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: Chart */
/* TITLE: Generating Hbar, Vbar, Block, Pie, and Star Charts */
/* PRODUCT: SAS */
/* SYSTEM: ALL */
/* KEYS: HISTOGRAM, BAR CHART, BLOCK CHART, PIE CHART, */
/* KEYS: STAR CHART, */
/* PROCS: CHART FREQ */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: */
/* MISC: */
/****************************************************************/
/* The following data step generates January 1979 daily */
/* revenues for a company with branches in four cities: */
/* Chicago, Los Angeles, New York, and Raleigh. Each branch */
/* reports revenues for three departments: 100, 115, and 314. */
/* PROC CHART is used to generate various hbar, vbar, block, */
/* and pie charts showing the distribution of revenues over */
/* branches and departments. */
options ls=78 ps=60 nodate;
data jan;
length c1-c4 city $ 15;
array c{4} $ c1-c4;
retain
c1 'Chicago, IL'
c2 'Los Angeles, CA'
c3 'New York, NY'
c4 'Raleigh, NC'
seed 080549;
month = 1;
year = 87;
keep city cityno dept date dow week weekinv revenue;
format date date7. revenue dollar8.;
/* Compute offsets and maxima */
fday = weekday( mdy( month, 1, year )) - 1;
if month ^= 12 then
maxdays = mdy( month + 1, 1, year ) - mdy( month, 1, year );
else
maxdays = 31;
lday = 7 - weekday( mdy( month, maxdays, year )) + 1;
maxweeks = ceil(( maxdays - 1 + lday ) / 7 );
/* For all cities, all departments, all weekdays, generate revenues */
do cityno = 1 to 4;
city = c{ cityno };
do dept = 100, 115, 314;
do day = 1 to maxdays;
date = mdy( month, day, year );
wkday = weekday( date );
if( 2 <= wkday <= 6 ) then do;
week = ceil(( fday + day( date )) / 7 );
weekinv = ceil(( maxdays - day + lday ) / 7 ) +
( 6 - maxweeks );
dow = put( date, weekdate9.);
dow = scan( dow, 1 );
dow = upcase( dow );
x = uniform( seed );
if x < .25 then
revenue = 1453 * uniform( seed );
else if .25 <= x <= .58 then
revenue = 1000 * uniform( seed );
else if .98 <= x <= .99 then
revenue = 2600 * uniform( seed );
else
revenue = 500 * uniform( seed );
p = 0;
if wkday = 3 or wkday = 6 then
p = .1;
if wkday = 4 then
p = .2;
if wkday = 5 then
p = .3;
revenue = p * revenue + revenue + cityno * 100;
output;
end;
end;
end;
end;
label dow = 'Day of the Week'
week = 'Week of the Month'
weekinv = 'Week of the Month';
run;
proc freq;
tables city*dept / nopercent norow nocol;
weight revenue;
run;
title1 'vbar dept / subgroup=city sumvar=revenue discrete;';
title2 '(vertical bar chart of revenue sums by dept and city)';
title4 'January 1987 Revenue Report';
proc chart;
vbar dept / subgroup=city sumvar=revenue discrete;
run;
proc chart;
hbar dept / subgroup=city sumvar=revenue discrete;
run;
title1 'hbar dept / group=city sumvar=revenue discrete;';
title2 '(horizontal bar chart of revenue sums by dept and city)';
title4 'January 1987 Revenue Report';
proc chart;
hbar dept / group=city sumvar=revenue discrete;
run;
title1 'block dept / group=city sumvar=revenue discrete;';
title2 '(block chart of revenue sums by dept and city)';
title4 'January 1987 Revenue Report';
proc chart;
block dept / group=city sumvar=revenue discrete;
run;
title1 'pie city / sumvar=revenue discrete;';
title2 '(pie chart of revenue sums by city)';
title4 'January 1987 Revenue Report';
proc chart;
pie city / sumvar=revenue discrete;
run;
title1 'pie city / type=mean sumvar=revenue discrete;';
title2 '(pie chart of mean revenue per day by city)';
title4 'January 1987 Revenue Report';
proc chart;
pie city / type=mean sumvar=revenue discrete;
run;
/* The data below represents total revenues for each month */
/* of 1987, for a rapidly growing company. PROC CHART is used */
/* to produce a star chart and a vertical bar chart showing */
/* revenues increasing over the year. Note the star chart may */
/* be thought of as simply a different sort of bar chart, with */
/* all the bars radiating from a central point. The principal */
/* advantage of the star chart in this example is it allows */
/* easy comparison of the last bar with the first. */
data jandec;
input month $ 1-3 revenue;
list;
cards;
Jan 362704
Feb 353000
Mar 400405
Apr 420550
May 450600
Jun 500765
Jul 500070
Aug 600065
Sep 750700
Oct 800770
Nov 944085
Dec 990550
;
title1 'star month / sumvar=revenue midpoints=''Jan''...';
title2 '(star chart of revenue per month)';
title4 'January 1987 Revenue Report';
proc chart;
star month / sumvar=revenue midpoints='Jan' 'Feb' 'Mar'
'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec';
format revenue dollar8.;
run;
title1 'vbar month / sumvar=revenue midpoints=''Jan''...';
title2 '(vertical bar chart of revenue per month)';
title4 'January 1987 Revenue Report';
proc chart;
vbar month / sumvar=revenue midpoints='Jan' 'Feb' 'Mar'
'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec';
format revenue dollar8.;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The FREQ Procedure
Table of city by dept
city dept
Frequency | 100| 115| 314| Total
----------------+--------+--------+--------+
Chicago, IL | 14318 | 15900 | 12491 | 42710
----------------+--------+--------+--------+
Los Angeles, CA | 18332 | 16111 | 16080 | 50524
----------------+--------+--------+--------+
New York, NY | 20445 | 17589 | 20510 | 58544
----------------+--------+--------+--------+
Raleigh, NC | 20875 | 20389 | 20095 | 61359
----------------+--------+--------+--------+
Total 73970.2 69989.9 69176.7 213137
vbar dept / subgroup=city sumvar=revenue discrete;
(vertical bar chart of revenue sums by dept and city)
January 1987 Revenue Report
revenue Sum
|
| RRRRR
$70,000 + RRRRR RRRRR
| RRRRR RRRRR RRRRR
| RRRRR RRRRR RRRRR
| RRRRR RRRRR RRRRR
| RRRRR RRRRR RRRRR
$60,000 + RRRRR RRRRR RRRRR
| RRRRR RRRRR RRRRR
| RRRRR RRRRR RRRRR
| RRRRR RRRRR RRRRR
| NNNNN RRRRR RRRRR
$50,000 + NNNNN NNNNN RRRRR
| NNNNN NNNNN NNNNN
| NNNNN NNNNN NNNNN
| NNNNN NNNNN NNNNN
| NNNNN NNNNN NNNNN
$40,000 + NNNNN NNNNN NNNNN
| NNNNN NNNNN NNNNN
| NNNNN NNNNN NNNNN
| NNNNN NNNNN NNNNN
| LLLLL LLLLL NNNNN
$30,000 + LLLLL LLLLL NNNNN
| LLLLL LLLLL LLLLL
| LLLLL LLLLL LLLLL
| LLLLL LLLLL LLLLL
| LLLLL LLLLL LLLLL
$20,000 + LLLLL LLLLL LLLLL
| LLLLL LLLLL LLLLL
| LLLLL CCCCC LLLLL
| CCCCC CCCCC LLLLL
| CCCCC CCCCC CCCCC
$10,000 + CCCCC CCCCC CCCCC
| CCCCC CCCCC CCCCC
| CCCCC CCCCC CCCCC
| CCCCC CCCCC CCCCC
| CCCCC CCCCC CCCCC
--------------------------------------------
100 115 314
dept
Symbol city Symbol city
C Chicago, IL L Los Angeles, CA
N New York, NY R Raleigh, NC
vbar dept / subgroup=city sumvar=revenue discrete;
(vertical bar chart of revenue sums by dept and city)
January 1987 Revenue Report
dept revenue
Freq Sum
|
100 |CCCCCCCLLLLLLLLLNNNNNNNNNNRRRRRRRRRR 88 $73,970
|
115 |CCCCCCCCLLLLLLLLNNNNNNNNNRRRRRRRRRR 88 $69,990
|
314 |CCCCCCLLLLLLLLNNNNNNNNNNRRRRRRRRRR 88 $69,177
|
----------+---------+---------+-------
$20,000 $40,000 $60,000
revenue Sum
Symbol city Symbol city
C Chicago, IL L Los Angeles, CA
N New York, NY R Raleigh, NC
hbar dept / group=city sumvar=revenue discrete;
(horizontal bar chart of revenue sums by dept and city)
January 1987 Revenue Report
city dept revenue
Freq Sum
|
Chicago, IL 100 |******************* 22 $14,318
115 |********************* 22 $15,900
314 |***************** 22 $12,491
|
Los Angeles, CA 100 |************************ 22 $18,332
115 |********************* 22 $16,111
314 |********************* 22 $16,080
|
New York, NY 100 |*************************** 22 $20,445
115 |*********************** 22 $17,589
314 |*************************** 22 $20,510
|
Raleigh, NC 100 |**************************** 22 $20,875
115 |*************************** 22 $20,389
314 |*************************** 22 $20,095
|
--------+-------+-------+----
$6,000 $12,000 $18,000
revenue Sum
block dept / group=city sumvar=revenue discrete;
(block chart of revenue sums by dept and city)
January 1987 Revenue Report
Sum of revenue by dept grouped by city
___ ___ ___
/_ /| /_ /| /_ /|
|**| | |**| | |**| |
|**| | |**| | |**| |
|**| | |**| | |**| |
|**| | |**| | |**| |
|**| | |**| | |**| |
___ -|**| |--------|**| |---___ -|**| |-------
/_ /| |**| | / |**| | /_ /| |**| | /
|**| | |**| | ___ |**| | |**| | |**| | /
Raleigh, NC |**| | |**| | /_ /| |**| | |**| | |**| | /
|**| | |**|/ |**| | |**|/ |**| | |**|/ /
|**| | |**| | |**| | /
|**| |$20,875 |**| |$20,389 |**| |$20,095 /
/|**| |-------/|**| |-------/|**| |-------/
___ |**| | / |**| | / |**| | /
/_ /| |**| | ___ |**| | ___ |**| | /
New York, NY |**| | |**| | /_ /| |**| | /_ /| |**| | /
|**| | |**|/ |**| | |**|/ |**| | |**|/ /
|**| | |**| | |**| | /
|**| |$20,445 |**| |$17,589 |**| |$20,510 /
/|**| |-------/|**| |-------/|**| |-------/
/ |**| | / |**| | / |**| | /
/ |**| | ___ |**| | / |**| | /
Los Angeles, CA ___ |**| | /_ /| |**| | / |**| | /
/_ /| |**|/ |**| | |**|/ ___ |**|/ /
|**| | |**| | /_ /| /
|**| |$18,332 |**| |$16,111 |**| |$16,080 /
city /|**| |-------/|**| |-------/|**| |-------/
/ |**| | / |**| | / |**| | /
/ |**| | / |**| | / |**| | /
Chicago, IL / |**| | / |**| | / |**| | /
/ |**|/ / |**|/ / |**|/ /
/ / / /
/ $14,318 / $15,900 / $12,491 /
/-------------/-------------/-------------/
100 115 314
dept
pie city / sumvar=revenue discrete;
(pie chart of revenue sums by city)
January 1987 Revenue Report
Sum of revenue by city
Los Angeles, CA ***********
**** ****
*** .. ***
** . **
** . ** Chicago, IL
* $50,524 . *
** 23.70% . **
* . $42,710 *
* . . . 20.04% *
** . .. . **
* .. . . *
* . . *
* + . . .. . .. . .. *
* *
* . *
** $58,544 . **
* 27.47% . *
* . $61,359 *
New York, NY ** . 28.79% **
* . *
** . **
** . **
*** . *** Raleigh, NC
**** . ****
***********
pie city / type=mean sumvar=revenue discrete;
(pie chart of mean revenue per day by city)
January 1987 Revenue Report
Mean of revenue by city
Los Angeles, CA ***********
**** ****
*** .. ***
** . **
** . ** Chicago, IL
* $766 . *
** 23.70% . **
* . $647 *
* . . . 20.04% *
** . .. . **
* .. . . *
* . . *
* + . . .. . .. . .. *
* *
* . *
** $887 . **
* 27.47% . *
* . $930 *
New York, NY ** . 28.79% **
* . *
** . **
** . **
*** . *** Raleigh, NC
**** . ****
***********
star month / sumvar=revenue midpoints='Jan'...
(star chart of revenue per month)
January 1987 Revenue Report
Center = $0 Sum of revenue by month Outside = $990,550
Apr
$420,550
May ************* Mar
$450,600 ***** ***** $400,405
*** ***
*** ***
** **
* *
** **
* *
Jun ** ** Feb
$500,765 * * $353,000
* .*.....*.. *
** .... . ...* **
* .. .. . ... *
** *. .. . .. . **
* .. ... .. . .. .* *
* . ... ... .. ... . *
* .. .......... . *
Jul * *.............+.........*. * Jan
$500,070 * . ......... . * $362,704
* . ... . . . ... ... *
* .. ... . . . .... .. *
** . ... . . . .. .. **
* *. . . . .... .. *
** .. . . . ..... **
* . . . . .... *
* . . . . .*
Aug * . . . . .. Dec
$600,065 * ... . . ..* $990,550
** *. . . ..**
* .... . . .. *
** ... . . .. **
*** ..*.............*.**
*** ***
Sep ***** ***** Nov
$750,700 ************* $944,085
Oct
$800,770
vbar month / sumvar=revenue midpoints='Jan'...
(vertical bar chart of revenue per month)
January 1987 Revenue Report
revenue Sum
$1,000,000 + ***
| ***
| *** ***
| *** ***
$900,000 + *** ***
| *** ***
| *** ***
| *** ***
$800,000 + *** *** ***
| *** *** ***
| *** *** *** ***
| *** *** *** ***
$700,000 + *** *** *** ***
| *** *** *** ***
| *** *** *** ***
| *** *** *** ***
$600,000 + *** *** *** *** ***
| *** *** *** *** ***
| *** *** *** *** ***
| *** *** *** *** ***
$500,000 + *** *** *** *** *** *** ***
| *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** ***
$400,000 + *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
$300,000 + *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
$200,000 + *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
$100,000 + *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
| *** *** *** *** *** *** *** *** *** *** *** ***
---------------------------------------------------------------
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
month
This sample uses PROC CHART to generate HBAR, VBAR, BLOCK, PIE, and STAR charts.
| Type: | Sample |
| Topic: | Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Pie Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Bar Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Star SAS Reference ==> Procedures ==> CHART
|
| Date Modified: | 2011-04-05 10:59:10 |
| Date Created: | 2005-05-23 13:47:12 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |