Sample 24889: Control the width of bars based on a data set value with PROC GCHART
The sample uses PROC GCHART with Annotate to vary the width of the bars in a vertical bar chart depending upon the values of a data set variable.
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 sample uses PROC GCHART with Annotate to vary the width of the bars in a vertical bar chart depending upon the values of a data set variable.
The graphics output in the Results tab was produced using SASĀ® 9.2. Submitting
the sample code with releases of SAS prior to SAS 9.2 might produce different results.
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Create the input data set A */
data a;
input Xvar Yvar Size_Var Colors $;
datalines;
5 10 5 vibg
10 20 10 depk
15 30 20 mob
;
run;
/* Create the annotate data set ANNO. */
data anno;
length color function style $8;
retain xsys '2' when 'a';
set a;
color=put(colors,8.);
function='move'; xsys='2';
x=xvar; ysys='1'; y=0;
output;
function='move'; xsys='7';
x=-1*(size_var/2);
output;
/* The BAR function is used to draw a fillable rectangle whose */
/* lower-left corner is defined by the internal variables */
/* (XLAST,YLAST) and whose upper-right corner is defined by the */
/* (X,Y) variable pair. */
function='bar'; line=0; style='solid';
x=-1*x*2; ysys='2'; y=yvar; output;
run;
/* Use a footnote statement to simulate */
/* a legend. */
footnote1 f='Albany AMT' c=black 'Legend ' c=vibg f=marker 'U'
f='Albany AMT' c=black ' Val-1 ' c=depk f=marker 'U'
f='Albany AMT' c=black ' Val-2 ' c=mob f=marker 'U'
f='Albany AMT' c=black ' Val-3 ';
footnote2 ' ';
/* Define empty pattern for the bars. The color of the bars */
/* will be the same as the background color of the graph so */
/* that the bars will not be visible. */
pattern1 v=empty c=white r=3;
/* Add a title to the graph */
title1 'Bar widths based on data set values';
/* Define axis characteristics */
axis1 order=(5 to 15 by 5) offset=(5,5)pct minor=none;
axis2 order=(0 to 50 by 10) minor=none;
/* Produce the chart by using the ANNO= */
/* option on the VBAR statement. */
proc gchart data=a;
vbar xvar / sumvar=yvar discrete anno=anno
maxis=axis1 raxis=axis2;
run;
quit;
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 sample uses PROC GCHART with Annotate to vary the width of the bars in a vertical bar chart depending upon the values of a data set variable.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> GCHART Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Annotation Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Bar
|
Date Modified: | 2005-08-24 16:06:29 |
Date Created: | 2004-11-11 11:07:55 |
Operating System and Release Information
SAS System | SAS/GRAPH | All | n/a | n/a |