add spices to your graphs using the annotate facilityal · add spices to your graphs using the...

16
1 Add Spices to Your Graphs Using the Annotate Facility Qingfeng Liang, Community Care Behavioral Health Organization, Pittsburgh, PA ABSTRACT One of the most powerful features in SAS ® /GRAPH is the Annotate facility. The Annotate facility uses a SAS data set to store the graphics instructions. Each observation in SAS data set corresponds to an instruction and the variables provide all information required to process each instruction. You can use the Annotate facility to add text, lines, bars, pie slices, or map to SAS/GRAPH procedure output. You can also produce custom graphics using the Annotate facility with the GSLIDE or GANNO procedures. It sounds complicated but you definitely can grasp it within couple hours after you are guided through the paper. The basic necessary elements for developing the Annotate facility are introduced nicely by asking five “W” questions. The paper also shows you a simple way to debug the Annotate data set. The paper shows how to place text on specific location and label data points for the X/Y plots through example. The elements of Bar charts are relabeled axis and a customized text is added through the Annotate facility. The Maps generated by GMAP can be added some spices using the Annotate facility. The paper also shows you how to place custom graphic elements or other graphic enhancements on large number of graphs automatically based on the data from the Annotate facility constructed. This will eliminate a lot of manual processes. INTRODUCTION One of the most powerful features in SAS/GRAPH is the Annotate facility. It can be used to overcome the limitations of SAS/GRAPH’s procedures by placing lines, bars, text, symbols etc. to any place on a graph to meet client’s specific needs. It adds the flexibility to enhance graphics output from many SAS/GRAPH procedures, including GCHART, GCONTOUR, GMAP, GPLOT, GPRINT, GRADAR, GSLIDE, and G3D. The paper goes through some examples to demonstrate an easy way to shorten the learning curve of applying Annotate Facility. SAS/GRAPH’S ANNOTATE FACILITY The Annotate facility is included within SAS/GRAPH and enables you to generate a special data set with specific variables of graphics commands from which you can produce graphics output. The power of the Annotate Facility is accessed through this special data set which is referred to as an Annotate data set. The first step of applying Annotate Facility is to create an Annotate data set. And then the next step is to tell SAS to execute the Annotate data set through SAS/GRAPH option within each graph procedure like: /ANNOTATE=<the name of Annotate data set> ANNOTATE DATA SET In order to create and use Annotate graphics, you must first understand the structure and functioning of the Annotate data set. The key of applying Annotate Facility is to create the Annotate data set which is an ordinary SAS data set with some predefined variables. The variables in an Annotate data set provide information about the position and attributes of the graphics element and they are required for processing each instruction. Annotate variables have fixed name and attributes and are assigned default values by the Annotate Facility if they have missing values or are not present in the data set. In an Annotate data set, each observation represents a command to draw a graphics element or to perform an action. The graphic elements drawn by these commands can be added to SAS/GRAPH output. You can use the Annotate facility to add (1) text of ant color, size, and font; (2) line segments of any length and thickness; (3) bars of any size, color, and fill pattern; (4) pie slices of any size, color, and fill pattern; (5) polygons of any shape, color, and fill pattern. And Now, Presenting ... NESUG 2009

Upload: hathuan

Post on 03-Jul-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

1

Add Spices to Your Graphs Using the Annotate Facility

Qingfeng Liang, Community Care Behavioral Health Organization, Pittsburgh, PA

ABSTRACT

One of the most powerful features in SAS®/GRAPH is the Annotate facility. The Annotate facility uses a SAS data set to store the graphics

instructions. Each observation in SAS data set corresponds to an instruction and the variables provide all information required to process each

instruction. You can use the Annotate facility to add text, lines, bars, pie slices, or map to SAS/GRAPH procedure output. You can also

produce custom graphics using the Annotate facility with the GSLIDE or GANNO procedures.

It sounds complicated but you definitely can grasp it within couple hours after you are guided through the paper. The basic necessary elements

for developing the Annotate facility are introduced nicely by asking five “W” questions. The paper also shows you a simple way to debug the

Annotate data set.

The paper shows how to place text on specific location and label data points for the X/Y plots through example. The elements of Bar charts are

relabeled axis and a customized text is added through the Annotate facility. The Maps generated by GMAP can be added some spices using

the Annotate facility.

The paper also shows you how to place custom graphic elements or other graphic enhancements on large number of graphs automatically

based on the data from the Annotate facility constructed. This will eliminate a lot of manual processes.

INTRODUCTION

One of the most powerful features in SAS/GRAPH is the Annotate facility. It can be used to overcome the limitations of SAS/GRAPH’s procedures by placing lines, bars, text, symbols etc. to any place on a graph to meet client’s specific needs. It adds the flexibility to enhance graphics output from many SAS/GRAPH procedures, including GCHART, GCONTOUR, GMAP, GPLOT, GPRINT, GRADAR, GSLIDE, and G3D.

The paper goes through some examples to demonstrate an easy way to shorten the learning curve of applying Annotate Facility.

SAS/GRAPH’S ANNOTATE FACILITY

The Annotate facility is included within SAS/GRAPH and enables you to generate a special data set with specific variables of graphics commands from which you can produce graphics output. The power of the Annotate Facility is accessed through this special data set which is referred to as an Annotate data set. The first step of applying Annotate Facility is to create an Annotate data set. And then the next step is to tell SAS to execute the Annotate data set through SAS/GRAPH option within each graph procedure like:

/ANNOTATE=<the name of Annotate data set>

ANNOTATE DATA SET

In order to create and use Annotate graphics, you must first understand the structure and functioning of the Annotate data set. The key of applying Annotate Facility is to create the Annotate data set which is an ordinary SAS data set with some predefined variables. The variables in an Annotate data set provide information about the position and attributes of the graphics element and they are required for processing each instruction. Annotate variables have fixed name and attributes and are assigned default values by the Annotate Facility if they have missing values or are not present in the data set.

In an Annotate data set, each observation represents a command to draw a graphics element or to perform an action. The graphic elements drawn by these commands can be added to SAS/GRAPH output. You can use the Annotate facility to add (1) text of ant color, size, and font; (2) line segments of any length and thickness; (3) bars of any size, color, and fill pattern; (4) pie slices of any size, color, and fill pattern; (5) polygons of any shape, color, and fill pattern.

And Now, Presenting ...NESUG 2009

2

Table 1 lists commonly used annotate variables. For a complete list of Annotate variables, please refer to the SAS/GRAPH documentation.

Annotate data sets follow the same rules for missing values as any other SAS data set. Variables that have a missing value use a default value. For example, if the COLOR variable has a missing value, then the first color in either the colors list that is defined by the COLORS= graphics option, if specified, or the device's default colors list is used.

Table 1. ANNOTATE DATA SET VARIABLES

VARIABLE DESCRIPTION FUNCTION specifies a drawing or programming action

X specifies a numeric horizontal coordinate

Y specifies a numeric vertical coordinate

Z specifies a numeric third dimensional coordinate; used with G3D procedure only XSYS specifies coordinate system for X or XC coordinates YSYS specifies coordinate system for Y or YC coordinates

ZSYS specifies coordinate system for Z coordinate (G3D procedure only) ANGLE angle of text label or starting angle of a pie slice

COLOR Color of a graphics primitive LINE line type to use in drawing or special control over pies and bars

POSITION placement and alignment for text strings

ROTATE angle at which to place individual characters in a text string SIZE size of an aspect of a graphics primitive; depends on FUNCTION variable (for TEXT, height of

characters; for PIE, pie slice radius; for DRAW, line thickness; and so on) STYLE font or pattern for a graphics element, depends on the FUNCTION variable

TEXT text to use in a label, symbol, or comment

WHEN whether a graphics element is drawn before or after procedure graphics output

HTML specifies link information for a drill-down graph

MIDPOINT Uses the value of the GCHART MIDPOINT= option in place of X or Y

group Uses the value of the GCHART GROUP= option in place of X or Y SUBGROUP Uses the value of the GCHART SUBGROUP= option in place of X or Y

FUNCTIONS

Like stated before each observation is corresponds to an instruction and the action within an instruction is given by FUNCTION. The is FUNCTION, which specifies what graphics element to draw (graphics primitive) or what action to take (programming function). For example, if you want to draw a line and the “DRAW” FUNCTION is needed. Table lists some of the common values of the variable “FUNCTION”.

Table 2. FUNCTIONS

FUNCTION DESCRIPTION

LABEL draw text MOVE move to the specified point (X,Y) DRAW draw a line from the current (X,Y) position

POINT draw a point SYMBOL draw a symbol

BAR draw a rectangle from the current (X,Y) position (see MOVE and TXT2CNTL); optionally, fill with a pattern

PIE draw pie slice, circle, or arc

POLY begin to draw a polygon (starting point) and, optionally, specify a fill color and pattern DEBUG Turn on trace of previous values and LIFO stack

And Now, Presenting ...NESUG 2009

3

COORDINATE SYSTEM

In the “Annotate Data Set Variables” table three variables (XSYS, YSYS, and ZSYS) are used to define which coordinate system is going to be used. You specify a coordinate system to use for each dimension, using the XSYS, YSYS, and ZSYS variables (for X, Y, and Z, respectively). Use ZSYS to annotate graphics output only from the G3D procedure. The Annotate Facility uses two different coordinates, absolute and relative and can recognize three different drawing areas (data, graphics output and procedure output) and for each drawing area there are two unit types (percentage, cells or value) associated with it. Therefore there are 12 different unique combinations coded as listed in Table3 below.

Table 3. Coordinate System

Coordinates Area Units Range Value Absolute data % 0-100% of axis 1

data values minimum to maximum of axis 2 graphics output area % 0-100% of graphics output area 3

graphics output area cells 0 to limit of graphics output area 4 procedure output area % 0-100% of procedure output area 5 procedure output area cells 0 to limit of procedure output area 6

Relative data % 0-100% of axis 7 data values minimum to maximum of axis 8

graphics output area % 0-100% of graphics output area 9 graphics output area cells 0 to limit of graphics output area A procedure output area % 0-100% of procedure output area B

procedure output area cells 0 to limit of procedure output area C

The following graph shows the areas under different coordinate system for the same graphic output.

STEPS TO CREATE ANNOTATE DATA SET

In order to take advantages of the annotate facility, the ultimate goal is to create an Annotate data set to instruct SAS/GRAPH to add graphics elements to your output. The following listed five “W” questions needs to be answered to guide you to create the data set easily.

And Now, Presenting ...NESUG 2009

4

(1) What am I doing? The only action variable is “FUNCTION”. We can view what you want to add to the graph is through a “FUNCTION”. It could be something like, “DRAW”, “MOVE”, “LABEL”, etc.

(2) Where do I get my X and Y (Data set)? X, Y, the positioning variables specify the point at which to draw the graphics element. The values can be manually assigned or can be generated from other data sets through data manipulation.

(3) What is my frame of reference? Xsys, Ysys, Zsys. Pick appropriate coordinate system to place elements to the desired location.

(4) What is special about my annotation? The attribute variables specify the characteristics of the graphics element (for example, color, size, line style, text font). Color, size, style, position, angle, rotation, text, line.

(5) When do I want to do my annotation? There are two choices, “before” or “after”. If “before” is chosen, graphic element is drawn before procedure graphics output.

DEBUGGING

The easiest way to debug Annotate data set is to count how many observations will be in the final annotate data set. As we learned before that each observation corresponds to a graphical instruction. How many instructions needed to decorate the graph will reflect by the number of observations in Annotate data set. PROC PRINT is a nice and easy way to check your final Annotate data set. You can examine the Annotation that you have specified or to debug your program. It provides complete information about the value that you specify for each variable in every observation. For more complex problems, the DEBUG function enables you to display the values of Annotate variables and internal coordinates before and after a function is submitted. The values are written to the SAS log.

ANNOTATE PLOT

Let’s first start with annotating plot. Figure 1 showed a plot which was generated with standard PROC GPLOT procedure. We would like to add an average line to the line plot and also label the value of average and the text “Overall Average=” in the plot.

Figure 1. Plot without annotated elements applied

At the very beginning we need to envision the steps or actions which are required to achieve the goal. It is similar to imagine what you are going to draw in a paper. First, move to the point where the average line will be drawn. Second, draw the average line. Third, label “Overall Average= “ above the line. Final step is to label the value of the average above the line. Basically four observations are required to annotate the plot. We will go through the five “W” questions to create these four observations step by step.

Step one: Move to the starting point of the line we are going to draw.

(1) What am I doing? “MOVE” (2) Where do I get my X and Y? X=0, Y=overall average

And Now, Presenting ...NESUG 2009

5

(3) What is my frame of reference? Xsys=1 (Horizontal reference line will have the same length as X axis, therefore coordinate system value 1 0-100% of x-axis will be used). Ysys=2 (value of axis will be used for y-axis)

(4) What is special about my annotation? Default (5) When do I want to do my annotation? Default

Step two: Draw the line

(1) What am I doing? “DRAW” (2) Where do I get my X and Y? X=100, Y=”overall average=” (3) What is my frame of reference? Xsys=1 Ysys=2 (4) What is special about my annotation? Color=red (5) When do I want to do my annotation? After

Step three: Label the text “Overall Average=”

(1) What am I doing? “LABEL” (2) Where do I get my X and Y (Data set)? X=40, Y=value of overall average (3) What is my frame of reference? Xsys=1 Ysys=2 (4) What is special about my annotation? Color=red style=swissl (5) When do I want to do my annotation? After

Step four: label the value of the overall average

(1) What am I doing? “LABEL” (2) Where do I get my X and Y (Data set)? X=68, Y==overall average (3) What is my frame of reference? Xsys=1 Ysys=2 (4) What is special about my annotation? Color=red (5) When do I want to do my annotation? After

Therefore, only 4 observations are needed in the annotate data set. The values for each observation are shown in the following screen shot of the Annotate table.

In this example you probably see how simple it would be to create an annotate data set and any enhancement you want to add to the graph could be converted into one or many graphic instructions labeled in this manner.

And Now, Presenting ...NESUG 2009

6

Figure 2. Labeling the line for overall average

ANNOTATE BAR CHART

Now we are interested in adding some spices to bar chart. For example, we have the bar graph generated by PROC GCHART like Figure 3.

Figure 3. Bart chart before Annotated elements applied

If label of each bar is needed to put on the top of the bar and the value of each group will be shown inside the bar, how we can achieve this? First we need to create observations to label the text to the top of the bar. Second, we will create observations to label the values inside the bars.

And Now, Presenting ...NESUG 2009

7

Step one: Label the text

(1) What am I doing? “label” and text=clinical_group (2) Where do I get my X and Y (Data set)? Midpoint=clinical_group, (3) What is my frame of reference? Xsys=2 Ysys=2 (4) What is special about my annotation? Color=blue (5) When do I want to do my annotation? After

Step two: Label the value

(1) What am I doing? “LABEL” and text=values of users (2) Where do I get my X and Y (Data set)? Midpoint=clinical_group, (3) What is my frame of reference? Xsys=2 Ysys=2 (4) What is special about my annotation? Color=blue (5) When do I want to do my annotation? After

Combining two steps, we will get the final annotate data set with 12 observations because there are six different groups and each group needs two instructions to label the text and the value separately. The details are shown in the attached SAS program. The final Annotate data set are show in the following table.

Figure 4. Labeling the each individual name and value for each bar

ANNOTATE MAP

We can use the annotate facility to label output from PROC MAP. For example, Community Care Behavioral Health Organization has six contracts to manage 35 counties Medicaid population within Pennsylvania and each contract covers different counties. We want to label each county’s abbreviation within each county and the counties under same contract will be filled by the same color. The following picture shows the final result we want to annotate.

And Now, Presenting ...NESUG 2009

8

Step One:

(1) What am I doing? “LABEL” the counties’ abbreviations (2) Where do I get my X and Y (Data set)? X and Y geographical coordination from maps.uscounty (3) What is my frame of reference? Xsys=2, ysys=2, hsys=3 (4) What is special about my annotation? Color=Black (5) When do I want to do my annotation? After

A user defined format is used to group different counties by the contracts and then different colors can be filled by the

contracts. The numbers of observations are dependent on how many counties we are going to show on the map. In

this example, 35 counties will be appeared the final map. The following screen shot show a portion of the Annotate

data set. You can refer to the attached SAS program for the details.

Figure 5. Labeling the counties and coloring by contracts

USING BY-GROUP PROCESSING WITH THE ANNOTATE FACILITY

You can use the Annotate facility with procedures that use BY statements to annotate each graph that is generated with a BY statement. The Annotate graphics for each graph are generated depending on the value of the BY variable. To use BY-group processing with the Annotate facility, your program must meet the following conditions:

And Now, Presenting ...NESUG 2009

9

(1) Both the input data set for the procedure and the Annotate data set must contain the same BY variable. (2) The BY variable must be defined as the same type (character or numeric) and length in both data sets. (3) If a label or format is associated with a BY variable in one data set, the same label or format has to be

associated with it in the other data set. (4) Both data sets must be sorted by the BY variable.

The ANNOTATE= option must be specified in an action statement in the procedure. If you specify the ANNOTATE= option in the PROC statement, the Annotate graphics are used for all graphs that are generated by the procedure rather than for unique values of the BY variable. Please refer to the attached SAS program for the details of how to generate multiple annotated graphs.

The following two graphs show that BY-Group processing is used to generate multiple annotated graph by different year. The detailed program is attached at the end of the paper.

Figure 6. Annotated Bar Chart for Year 2007

Figure 7. Annotated Bar Chart for Year 2008

CONCLUSION

The paper used several simple examples to demonstrate how to use the Annotate Facility to enhance SAS graph

output. An easy and practical method is used throughout the paper to show how easy to construct an Annotate data

set. Especially for those who are new to the Annotate Facility, it is a good way to start and it should help to ease the

learning curve. For those who are interested in exploring more and deeper about the Annotate Facility, please refer

the SAS/GRAPH documentation for more details.

And Now, Presenting ...NESUG 2009

10

REFERENCES

SAS Institute Inc. (2004). SAS/GRAPH Software : Reference, Version 9. Cary, NC 27513: SAS Institute Inc.

Carpenter, Art (1999). Annotate: Simply the Basics. Cary, NC: ASA Institute Inc.

Mink, D., Pasta, D. (2006). Improving Your Graphics Using SAS/GRAPH Annotate Facility. Paper 085-31, SUGI 31.

ACKNOWLEDGEMENTS

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies.

CONTACT INFORMATION

Your comments and questions are valued and encouraged. Contact the author at:

Qingfeng Liang, Lead Programmer Community Care Behavioral Health Organization Suite 700, Chatham One Center Pittsburgh, PA 15241 Tel: 412-402-8748 Fax: 412-454-2177 E-mail: [email protected] Web: www.ccbh.com

And Now, Presenting ...NESUG 2009

11

/**************************************************************

Program: annotated plot

Description: Add an overall average line to the plot and

label the text and the mean to the plot

Programmer: QFL

Date: 06/08/2009

***************************************************************/

proc means data=out.clinical_group noprint;

var units;

output out=avgunit(drop=_type_ _freq_) mean=avg_unit;

run;

data out.clinical_group;

set out.clinical_group;

if _N_=1 then set avgunit;

run;

data plotanno;

length color function style $8 text $16;

retain function 'label' xsys '1' ysys '2' hsys '1' when 'a';

set avg_unit;

function="move"; x=0; y=avg_unit; output;

function="draw"; x=100; color='red'; size=0.75; line=1; output;

function="label"; style='swissb'; x=35; size=6; position='3';

text='Overall Average='; output;

function="label"; style='swissb'; x=62; size=6; position='3';

text=put(avg_unit, 7.0); output;

run;

axis1 width=3 label=(j=r a=-90 r=90 h=1 'UNITS') minor=none;

axis2 width=3 label=(j=r h=1 'Month') minor=none;

proc gplot data=out.clinical_group;

title "Number of Units Per Month in 2008";

plot units*mos=clinical_subgroup / haxis=axis2 vaxis=axis1 noframe

anno=plotanno;

where 120 >= mos >=109 and clinical_subgroup not in("TSS");

symbol i=join c=black v=square h=2 l=1 w=3 ci=red ;

symbol2 i=join c=blue v=triangle h=2 l=5 w=3 ci=green ;

run;

quit;

And Now, Presenting ...NESUG 2009

12

/**************************************************************

Program: annotated bar chart

Description: Label the text to the top of the bars and

Label the value of each bar inside each bar

Programmer: QFL

Date: 06/08/2009

***************************************************************/

proc means data=dat.anno_bar_data;

by clinical_group;

var users

output out=group_sum(drop=_type_ _freq_) sum=;

run;

data bar_anno1;

length color function style $8;

retain xsys ysys "2" hsys "3" when "a";

set group_sum;

function="label";

midpoint=clinical_group;

text=clinical_group;

position='2';

color="blue";

style="swissb";

size=3;

run;

data bar_anno2;

length color function style $8;

retain xsys ysys "2" hsys "3" when "a";

set group_sum;

function="label";

midpoint=clinical_group;

text=put(users, 4.0);

position='8';

color="black";

style="swissb";

size=3;

run;

data bar_anno;

set bar_anno1 bar_anno2;

run;

axis1 label=none major=none minor=none style=0 value=none;

axis2 label=none value=none;

proc gchart data=dat.anno_bar_data;

title "Average Users By Clinical Group";

vbar clinical_group / sumvar=users raxis=axis1 maxis=axis2

anno=bar_anno noframe;

pattern v=solid c=cyan;

label clinical_group="Group";

run;

quit;

And Now, Presenting ...NESUG 2009

13

/**************************************************************

Program: annotated map

Description: Label the county’s abbreviation inside each

County and color counties by each contract

Programmer: QFL

Date: 06/08/2009

***************************************************************/

/* create PA map*/

proc format;

value countyfmt

1="AD" 3="AL" 11="BK" 15="BA"

23="CA" 25="CB" 27="CE" 29="CH"

31="CL" 33="CF" 37="CO" 47="EK"

53="FO" 61="HU" 65="JE" 67="JU"

69="LK" 79="LU" 83="MC" 87="MI"

89="MN" 93="MT" 97="NU" 103="PI"

105="PO" 107="SC" 109="SN" 113="SL"

115="SQ" 117="TI" 119="UN" 123="WA"

127="WN" 131="WY" 133="YO";

run;

proc means data=maps.uscounty noprint;

var x y;

by state county;

where state=42 and county IN( 1, 3, 11, 15, 23, 25, 27, 29, 31,

33, 37, 47, 53, 61, 65, 67, 69, 79, 83, 87, 89, 93, 97, 103,

105, 107, 109, 113, 115, 117, 119, 123, 127, 131, 133);

output out=counties(keep=state county x y) mean=;

run;

data pacounties;

length color function style $8 text $16;

retain function 'label' xsys ysys '2' hsys '3';

set counties;

color='black'; text=left(put(county, countyfmt.)); position='B';

when="a"; style='swissb'; output;

run;

proc format;

value regfmt

1="Capital" 3="Southwest" 11="Capital"

15="NorthCentral" 23="NorthCentral" 25="CMP"

27="NorthCentral" 29="Southeast" 31="NorthCentral"

33="NorthCentral" 37="NorthCentral" 47="NorthCentral"

53="NorthCentral" 61="NorthCentral" 65="NorthCentral"

67="NorthCentral" 69="NorthEast" 79="NorthEast"

83="NorthCentral" 87="NorthCentral" 89="CMP"

93="NorthCentral" 97="NorthCentral" 103="CMP"

105="NorthCentral" 107="NorthCentral" 109="NorthCentral"

113="NorthCentral" 115="NorthEast" 117="NorthCentral"

119="NorthCentral" 123="NorthCentral" 127="NorthCentral"

131="NorthEast" 133="Capital";

run;

And Now, Presenting ...NESUG 2009

14

goptions reset=all;

goptions device=gif transparency border hsize=7.6in vsize=8.75 in;

proc gmap data=counties map=maps.uscounty;

title "Community Care Contracted Regions";

where state=42 and county IN( 1, 3, 11, 15, 23, 25, 27, 29, 31,

33, 37, 47, 53, 61, 65, 67, 69, 79, 83, 87, 89, 93, 97,

103, 105, 107, 109, 113, 115, 117, 119, 123, 127, 131, 133);

id county;

choro county / discrete coutline=black cempty=black annotate=pacounties

legend=legend1;

format county regfmt.;

pattern1 v=ms c=cyan;

pattern2 v=ms c=maroon;

pattern3 v=ms c=orange;

pattern4 v=ms c=blue;

pattern5 v=ms c=Green;

legend1 label=("Regions") frame;

run;

quit;

And Now, Presenting ...NESUG 2009

15

/**************************************************************

Program: Multiple Annotated Graphs

Description: Generating multiple annotated graphs with BY

processing

Programmer: QFL

Date: 06/08/2009

***************************************************************/

proc sort data=dat.anno_bar_by_data;

by year clinical_group;

run;

proc means data=dat.anno_bar_by_data;

by year clinical_group;

var users;

output out=group_sum(drop=_type_ _freq_) sum=;

run;

data bar_anno1;

length color function style $8;

retain xsys ysys "2" hsys "3" when "a";

set group_sum;

function="label";

midpoint=clinical_group;

text=clinical_group;

position='2';

color="blue";

style="swissb";

size=3;

run;

data bar_anno2;

length color function style $8;

retain xsys ysys "2" hsys "3" when "a";

set group_sum;

function="label";

midpoint=clinical_group;

text=put(users, 4.0);

position='8';

color="black";

style="swissb";

size=3;

run;

data bar_anno;

set bar_anno1 bar_anno2;

run;

proc sort data=bar_anno;

by year;

run;

goptions hsize=8 in vsize=5 in;

axis1 label=none major=none minor=none style=0 value=none;

axis2 label=none value=none;

proc gchart data=dat.anno_bar_by_data;

And Now, Presenting ...NESUG 2009

16

title "Average Users By Clinical Group";

vbar clinical_subgroup / sumvar=users raxis=axis1 maxis=axis2

anno=bar_anno noframe;

by year;

pattern v=solid c=cyan;

label clinical_group="Group";

run;

quit;

And Now, Presenting ...NESUG 2009