Sample 24865: Overlay a plot line on a vertical bar chart
/*************************************************************************/
/* This example has 2 separate programs, both of which use ANNOTATE to */
/* overlay a plot line on a vbar. The first example is of a non-stacked */
/* vbar and the second program is of a stacked vbar, both are overlayed */
/* with a plot line created by the ANNOTATE facility. */
/*************************************************************************/
/* Example 1 */
goptions reset=all ftext=swissb;
/* Create input data set, A for Example 1 */
data a;
input xvar mmddyy6. vbar_y plot_y;
datalines;
010196 10 8
020196 20 15
030196 30 20
040196 40 36
050196 50 42
;
/* The next few lines in the ANNO data step create the plot line that */
/* will overlay the vbar. XSYS and YSYS are the coordinate system */
/* variables used to position the x and y values. The annotate data */
/* set will use one MOVE function for the first observation, then */
/* it will use the DRAW function to draw each line segment from one */
/* vbar to the next. */
data anno;
length function color $8 text $10;
retain xsys ysys '2' when 'a';
set a end=last;
if _n_ = 1 then function='move';
else function='draw'; xsys='2';ysys='2';
x=xvar; y=plot_y; output;
function='symbol';xsys='2';ysys='2';x=xvar;y=plot_y;text='dot';size=2;color='red';
output;
run;
/* Assign pattern characteristics */
pattern v=s c=blue;
/* Assign axis definitions */
axis1 label=('Month');
axis2 label=('Sales');
/* Produce the chart */
proc gchart data=a;
vbar xvar / sumvar=vbar_y anno=anno midpoints='01jan96'd to '01may96'd by month
maxis=axis1 raxis=axis2;
format xvar monname3.;
format vbar_y dollar6.;
footnote1 ' ';
run;
quit;
/* Example 2 */
goptions reset=all;
/* Create input data set, A for Example 2 */
data a;
input subvar $ xvar mmddyy6. vbar_y plot_y;
datalines;
sub1 010196 10 8
sub1 020196 20 15
sub1 030196 30 55
sub1 040196 40 50
sub1 050196 50 40
sub2 010196 10 8
sub2 020196 20 15
sub2 030196 30 55
sub2 040196 40 50
sub2 050196 50 40
;
/* The next few lines in the ANNO data step create the plot line that */
/* will overlay the vbar. XSYS and YSYS are the coordinate system */
/* variables used to position the x and y values. The annotate data */
/* set will use one MOVE function for the first observation, then */
/* it will use the DRAW function to draw each line segment from one */
/* vbar to the next. */
data anno;
length function color $8 text $10;
retain xsys ysys '2' color 'red' when 'a' size 4;
set a end=last; by subvar;
if first.subvar then function='move'; else function='draw';
x=xvar; y=plot_y; output;
function='symbol';xsys='2';ysys='2';x=xvar;y=plot_y;text='dot';size=2;color='red';
output;
run;
/* Assign pattern characteristics */
pattern1 v=s c=blue;
pattern2 v=s c=green;
/* Assign axis definitions */
axis1 label=('Month');
axis2 label=('Sales');
/* Assign legend characteristics */
legend1 label=('Actual') value=('1st Qtr' '2nd Qtr');
/* Produce the chart */
proc gchart data=a;
vbar xvar / sumvar=vbar_y anno=anno midpoints='01jan96'd to '01may96'd by month
subgroup=subvar maxis=axis1 raxis=axis2 legend=legend1;
footnote ' ';
format xvar monname3.;
format vbar_y dollar6.;
run;
quit;

This example has 2 separate programs, both of which use ANNOTATE to
overlay a plot line on a vbar. The first example is of a non-stacked
vbar and the second program is of a stacked vbar, both are overlayed
with a plot line created by the ANNOTATE facility.
| Type: | Sample |
| Topic: | Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Bar SAS Reference ==> Procedures ==> GCHART
|
| 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 |