Sample 24867: Producing and labeling a population tree
/* Producing and Labeling a Population Tree */
/* Set graphics options */
goptions reset=global gunit=pct cback=blue colors=(white)
htext=3 ftext=zapf;
/* Create the data set, MILEAGE. Mileage contains the number of */
/* miles driven by males and females in certain age categories. */
data mileage;
input age $ sex $ amount;
datalines;
65-up M 7199
65-up F 4502
55-64 M 12304
55-64 F 5428
45-54 M 15701
45-54 F 6915
35-44 M 17916
35-44 F 7653
25-34 M 16683
25-34 F 7124
16-24 M 10718
16-24 F 6047
;
/* Convert the data values for one group to negative values to */
/* create the input data set, CONVERT. CONVERT contains the same */
/* variables as MILEAGE; however, the values of AMOUNT for the */
/* female drivers are made negative to force a zero reference line */
/* in the bar chart. */
data convert;
set mileage;
if sex='F' then amount=-amount;
run;
/* Create a format for the values of AMOUNT. The POSVAL. format */
/* adds a comma and suppresses the sign on the values so that */
/* negative values appear as positive values. */
proc format;
picture posval low-high='000,009';
run;
/* Create the Annotate data set, ANLABELS. ANLABELS adds the */
/* labels to the bars. Because data values are used to place */
/* the labels, XSYS and YSYS use the absolute data coordinate */
/* system, 2. A value of A for WHEN causes the labels to */
/* overlay the chart. */
data anlabels(drop=age sex amount);
length text $ 8;
retain function 'label' when 'a' xsys ysys '2' hsys '3' size 4;
set convert;
midpoint=age; subgroup=sex;
/* The values for AGE and SEX, from the CONVERT data set, */
text=left(put(amount, posval.));
/* positions the labels. AMOUNT from CONVERT determines */
/* the text of the labels. */
if sex ='F' then position='>';
/* POSITION changes depending on the group that */
else position='<'; output;
/* is being labeled. */
run;
/* Add the title and footnote */
title1 font=zapfb height=6.5 'Average Miles Driven Annually';
footnote1 font=swissl height=2.5 justify=left ' SAS/GRAPH'
move=(+0,+.5) '02'x move=(+0,-.5) ' Software'
justify=right 'DRIVER ';
/* Modify the appearance of the axes. In the AXIS2 statement, */
/* the VALUE= option suppresses the third tick mark so that the */
/* range for each group is zero to the maximum value. */
axis1 label=(justify=left 'Age') style=0;
axis2 label=none value=(tick=3 '') minor=none major=none
width=3 order=(-10000 to 20000 by 10000);
/* Define patterns for the bars. Patterns are assigned to the */
/* subgroups in order of the values of the subgroup variable, SEX. */
pattern1 value=solid color=cyan;
pattern2 value=solid color=magenta;
/* Produce the bar chart. */
proc gchart data=convert;
format amount posval.; /* The FORMAT statement applies the POSVAL. format*/
/* to the values of AMOUNT. */
note move=(25,78) height=4 'Women' move=(+3.5,+0) 'Men';
/* The NOTE statement places the labels */
/* "Women" and "men" above the population */
/* tree. */
hbar age / sumvar=amount discrete nostat subgroup=sex
maxis=axis1 raxis=axis2 nolegend annotate=anlabels;
/* In the HBAR statement, SUBGROUP= */
/* names the variable that determines */
run; /* the groups, and ANNOTATE= includes */
quit; /* the annotation defined in the */
/* ANLABELS data set. */

This example produces a population tree that compares average miles driver by men and women. The data values for one group of drivers are made negative to force GCHART to add a zero reference line. The negative values appear positive because a format is used to display the values.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GCHART Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Special Charts
|
| Date Modified: | 2005-08-24 16:06:25 |
| Date Created: | 2004-11-11 11:07:52 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |