Image483_fmt.png

Chapter 10 Presentation Graphics—More than Just SAS/GRAPH

10.1 Generating Box Plots

10.1.1  Using PROC BOXPLOT

10.1.2  Using PROC GPLOT and the SYMBOL Statement

10.1.3  Using PROC SHEWHART

10.2 SAS/GRAPH Specialty Techniques and Procedures

10.2.1  Building Your Own Graphics Font

10.2.2  Splitting a Text Line Using JUSTIFY=

10.2.3  Using Windows Fonts

10.2.4  Using PROC GKPI

10.3 PROC FREQ Graphics

SAS/GRAPH software has had the ability to create presentation-quality graphs since its introduction. Currently within SAS there are several graphing systems, with some of the newest innovations associated with ODS Statistical Graphics. Outside of these two graphics systems there are a number of procedures that have plotting and graphing capabilities that are comparable to SAS/GRAPH. A well-rounded programmer will be aware of each of these systems and will be able to take advantage of the strengths of each. This chapter briefly discusses the plotting capabilities of some procedures that are not part of SAS/GRAPH.

MORE INFORMATION

The plotting capability of PROC UNIVARIATE (see Sections 8.2.1 through 8.2.3) and PROC REG (see Sections 9.3 and 9.4) are demonstrated in other sections of the book.

A review of the SYMBOL, AXIS, and LEGEND statements, which are used throughout this chapter, can be found in Chapter 9.

SEE ALSO

Carpenter (2010b) demonstrates a number of these procedures along with a variety of capabilities. SAS has extensive graphing capabilities that are not covered in this book. Introductions to SAS/GRAPH can be found in Carpenter and Shipp (1995) and Miron (1995). The annotate facility is introduced in Carpenter (1999). ODS Graphics and Statistical Graphics are described in the books by Kuhfeld (2010), as well as Matange and Heath (2011).

10.1 Generating Box Plots

A box plot is a type of graph that has been used to display more than two dimensions worth of information on a single graph. Unlike some other graphics techniques that also attempt to display more than two dimensions, the box plot can do so without creating visual distortions that otherwise can mislead the reader (Carpenter 1994 and Carpenter 1995, Section 5.7). Although used heavily in some disciplines, they are unfortunately ignored in others.

Traditionally, the number of ways to generate a box plot within SAS was fairly limited. User-written programs were common with some of the more sophisticated published examples presented by Michael Friendly (Friendly, 1991). The SYMBOL statement within SAS/GRAPH can also be used to generate box plots; however, even with the addition of recent options this is still a limited technique. More recent additions to SAS provide procedures that can be used to generate box plots. Of these, the only procedure dedicated to the generation of box plots is PROC BOXPLOT (see Section 10.1.1), which is part of SAS/STAT software. Other procedures that generate variations of this type of data display include:

  • PROC GPLOT

SAS/GRAPH

(using the SYMBOL statement, see Section 10.1.2)

  • PROC MIXED

SAS/STAT

  • PROC SHEWART

SAS/QC

(see Section 10.1.3)

SEE ALSO

The programs and macros found in Michael Friendly’s book (Friendly, 1991) are well written and well explained. The techniques described provide a flexibility that is hard to beat even in the newer procedures.

10.1.1 Using PROC BOXPLOT

PROC BOXPLOT, a fairly recent addition to SAS/STAT software, is used to create a variety of types of box plots. The PLOT statement is used to provide primary control, and PLOT statement options in addition to those shown in the example below include:

  • BOXSTYLE

indicates the type of box to be displayed

  • BOXWIDTH

used to control the box width

  • BOXWIDTHSCALE

allows box width to vary according to a function of the group size

  • NOTCHES

draws the boxes with notches

  • SYMBOLLEGEND

attaches a legend statement (see Section 9.3.2)

Although this is a SAS/STAT procedure, it has the capability of utilizing statements that are normally associated with SAS/GRAPH. These include the SYMBOL, AXIS, and LEGEND statements (see Section 9.3).

symbol1 color = blue h = .8 v=dot;
axis1 minor=none color=black
      label=(angle=90 rotate=0);
proc boxplot data=demog;
   plot wt*symp/ cframe  = cxdedede Callout 1
                 boxstyle = schematicid Callout 2
                 cboxes   = red
                 cboxfill = cyan
                 vaxis    = axis1 Callout 3
                 ;
   id race; Callout 4
   run;

Callout 1 The background color inside of the frame is set to gray using the color CXdedede.

Callout 2 There are several styles of boxes. SCHEMATICID causes points outside of the whiskers to be labeled using the ID variable, which is RACE Callout 4, in this graph.

Callout 3 The AXIS statement is used to control various aspects of the vertical axis. AXIS statements can be applied to either the horizontal axis, HAXIS=, or the vertical axis, VAXIS= (see Section 9.3).

Callout 4 The ID statement names the variable(s) used to identify the outlying points.

image shown here

In this example the SYMBOL statement has been used to control the color and symbol designating the mean (a blue dot). The median is designated with a horizontal line and the upper and lower limits of the box are the 25th and 75th percentiles.

10.1.2 Using PROC GPLOT and the SYMBOL Statement

The SYMBOL statement (see Section 9.3.1) can be used to generate box plots directly in the GPLOT procedure. The control is through the use of the INTERPOL= option, which is usually abbreviated as I=. When I= takes on the value of BOX, data are condensed into a box plot for constant values of the horizontal variable (SYMP).

symbol1 color = blue v=none i=box10 bwidth=3; Callout 1
symbol2 color = red  v=dot  i=none h=1.2;
axis1 minor=none color=black
      order=(50 to 250 by 50)
      label=(angle=90 rotate=0);
axis2 order = ('00' '01' '02' '03' '04' '05' Callout 2
               '06' '07' '08' '09' '10' '11')
      value = (t=1  ' ' t=12 ' '), Callout 3
proc gplot data=demog;
   plot wt*symp/ haxis   = axis2
                 vaxis   = axis1
                 ;
   run;

				

Callout 1 The boxes that form the box plot are defined using this SYMBOL statement. The options form the characteristics of the boxes:

  • Color=

identifies the outline color

  • Value=

indicates that plot symbols are not needed

  • Interpol=

requests box plots with the BOX option BOX10 whiskers are at the 10th and 90th percentiles

  • bwidth=

specifies the width of the boxes

image shown here

symbol1 color = blue v=dot i=box10 bwidth=3;
symbol2 color = red  v=dot  i=none h=1.2;
axis1 minor=none color=black
      order=(50 to 250 by 50)
      label=(angle=90 rotate=0);
axis2 order = ('00' '01' '02' '03' '04' '05' 
               '06' '07' '08' '09' '10' '11')
      value = (t=1  ' ' t=12 ' '),
proc shewhart data=demog;
   boxchart wt*symp/ 
      haxis   = axis2
      vaxis   = axis1
 stddeviations nolimits
      ;
   run;

Callout 2 The major tick marks for the horizontal axis are declared. ‘00’ and ‘11’ do not appear in the data and their labels are set to blank using the VALUE option Callout 3. They provide horizontal spacing control.

10.1.3 Using PROC SHEWHART

PROC SHEWHART, which is available in SAS/QC software, can be used to generate a number of process control charts, and box plots are one of the supported chart forms.

The following code can be used to create box plots using PROC SHEWHART. Note that the horizontal plot variable must be character.

The AXIS statements are used to augment the axes. Although SHEWHART and CAPABILITY are not SAS/GRAPH procedures, they support AXIS, SYMBOL, and PATTERN statements.

image shown here

image shown here

symbol1 color = blue v=dot h=2;

You can also use the ANNOTATE facility with these procedures.

10.2 SAS/GRAPH Specialty Techniques and Procedures

SAS/GRAPH software has been a product of SAS software for quite a long time. During that time not only has its capabilities continued to expand, but so have the technologies to which it is delivering. As a result there are a great many graphics problems that have been solved over the years. Here are a few of the more interesting.

10.2.1 Building Your Own Graphics Font

Although the plot symbols available through SAS/GRAPH software are generally adequate for our graphing needs, occasionally you may want to tailor plot symbols for specific needs. The GFONT procedure can be used to create plot symbols. The procedure is used to draw the symbol shape in much the same way as the annotate facility is used to draw, that is by drawing from one coordinate to the next.

In this example we are not satisfied with the ‘lumpy’ appearance of the dot symbol, and would like to create a smoother symbol. This portion of a graph was generated using the standard DOT symbol.

We can smooth out the circle by generating our own symbol using PROC GFONT.

image shown here

A control data set that draws the font characters (in this case just a circle) is first generated in a DATA step. Like annotate data sets, specific variables are used to pass information to the GFONT procedure. Here we are drawing the outline of a circle using 721 short line segments. This control data set is then passed to GFONT.

data fontdata(keep=char seg x y lp ptype);
retain char 'c' Callout 1      
       seg   1  Callout 2    
       lp   'p';Callout 3
ptype='w'; x=-10; y=110; output fontdata;Callout 4
ptype='v'; x=100; y=50;  output fontdata;Callout 5
do deg = 0 to 360 by .5;   
   rad = deg*arcos(-1)/180;   
   x=50*cos(rad)+50; 
   y=50*sin(rad)+50; 
   output fontdata; Callout 6
end;
run;
libname gfont0 "&pathdata"; Callout 7
proc gfont data=fontdata
            name=mydot Callout 8 
            filled Callout 9
            resolution=3; Callout 10  
run;
symbol1 f=mydot Callout 8 c=blue v='c' Callout 1 h=1;

Callout 1 The variable CHAR is used to hold the keyboard character ‘c’ used to designate this symbol within the MYDOT font Callout 8.

Callout 2 Symbol segments allow you to create symbols with disconnected parts (segments). This symbol has only one segment so this value is a constant.

Callout 3 This is to be a polygon figure.

Callout 4 Width of the character (PTYPE=’w’). The symbol will have a width of 100 units. Allow about 10% extra for character spacing.

Callout 5 This is the first coordinate of the plot symbol ( PTYPE=’v’).

Callout 6 The segment is written to the control data set.

Callout 7 Generated fonts are stored in a catalog named FONTs. SAS/GRAPH software searches for this catalog in numbered librefs whose names start with GFONT.

Callout 8 Name the font.

Callout 9 We want the shape to be filled.

Callout 10 Increase the font resolution. You may notice little or no difference between a value of 1 and 3.

The resulting dots are a bit smoother. In this screen capture some pixelation has taken place when the image was copied into this document.

image shown here

SEE ALSO

Carpenter (1995) uses PROC GFONT to create a logo and sunflower symbols that self adjust according to the plotted value. Plot symbol resolution was further discussed with alternate solutions in the SAS Forum thread at http://support.sas.com/forums/thread.jspa?threadID=12547&start=0&tstart=0.

10.2.2 Splitting a Text Line Using JUSTIFY=

Within SAS/GRAPH software you can use the text justification option to split lines of text. Very often this technique can be used where you otherwise would be unable to split the text line. All that you need to do is to repeat the justification option. The second occurrence will cause a line split.

title1 f=arial h=1.2 justify=c '10.2.2' 
                     j=center 'Splitting Text'; Callout 1
symbol1 c=blue v=dot h=1.5;
symbol2 c=red v=dot h=1.5;
axis1 reflabel = (h=1.5
                t=1 c=red  j=left 'Overweight' Callout 2
                           j=l ' ' 
                           j=l c=blue  'Normal'), 
axis2 order=(1920 to 1970 by 10)
      label=(j=c 'Birthyear'j=c 'All Subjects'), Callout 3


Callout 1 The justification option can be written as either JUSTIFY or abbreviated as a J. The position (Left, Center, or Right) can also be abbreviated. Here the repeated justification option causes a split in the text of the title.

image shown here

Callout 2 The reference label on the vertical reference line has been split into three text lines.

Callout 3 The horizontal axis label has been split into two lines.

10.2.3 Using Windows Fonts

SAS/GRAPH software has a number of built-in fonts. In addition if you are executing in the Windows environment, you may also use Windows TrueType fonts.

The GOPTIONS statement (see Section 9.2) is used to specify graphics options, and one of these options, the FTEXT= option, can be used to specify fonts. On titles the FONT= option (see Section 9.1) can also be used to specify fonts.

goptions reset=all noborder
         device=emf
         gsfname=image gsfmode=replace
         ftext='Arial'; Callout 1
title1 f=arial 'This is a Title'; Callout 2

Callout 1 Arial has been selected as the default font for all graphics text. As a general rule, fonts that are not SAS/GRAPH fonts should be quoted when they are named as a graphics option. The name must be quoted when it has more than one word.

Callout 2 The font for a title can also be specified (see Section 9.1 for more on TITLE statement options). It is not necessary to quote the font name in the TITLE statement, unless the font name has more than one word, e.g., ‘Times New Roman’.

You can see a list of available fonts, and their alternate designations, by selecting the FONTS entry in the Windows control panel. Select Start Control Panel Fonts.

Some fonts have named variations that include bold and italics (‘Arial Bold’). You may also want to specify font modifiers. Of the three available font modifiers, bold (/bold or /bo Callout 3) and italic (/italics or /it), are the most commonly used.

image shown here

axis1 label=(f='arial/bo Callout 3' angle=90 rotate=0 'Patient Weight'),
symbol1 c=blue 
        f='wingdings 2' v='ð' Callout 6
        i=box10 bwidth=3;

There are a number of symbol sets that are included with SAS/GRAPH software. For symbol sets other than the default symbol set, the name of the symbol set is specified with the FONT= (or F=) option on the SYMBOL statement. For special characters that are not SAS/GRAPH special characters (characters that do not have a value mapped to the keyboard), the character can often be inserted from the character map (shown to the right). Select Start Programs Accessories System Tools Character Map. Callout 4 Select the character of interest; as shown on the right, a starburst design from the Wingdings 2 font has been selected. Callout 5 Press the copy button to place the code in the paste buffer. Callout 6 Paste the value into the appropriate location (the V= option on the SYMBOL statement is shown here). Notice that the symbol is likely to appear differently in the SAS program than it will in the graph.


CAVEAT: If you choose a non-standard font that is only available on your local machine, your SAS program becomes less transportable.

10.2.4 Using PROC GKPI

The GKPI (Key Performance Indicator) procedure is fairly new to SAS/GRAPH. This procedure allows you to quickly build indicator bars or dials that show the relative status of a value within a range that you have specified. There are several types of performance indicators available through this procedure. The horizontal slider (HBULLET) is shown here. You can specify the range of values, colors to separate ranges, and the current value.

image shown here


				
goptions reset=all noborder 
         device=javaimg Callout 1
         xpixels=130 ypixels=50 
         ftext='Arial';


The JAVAIMG device Callout 1 is required for the construction of the indicator. Here the GOPTION statement also sets the horizontal (XPIXELS) and vertical (YPIXELS) size in pixels.

Each execution of the procedure generates a single indicator graphic; therefore, for practical applications the GKPI procedure step will need to be called within a macro loop of some kind.

%macro slider(gname,bmi);
proc gkpi mode=raised;
hbullet actual=&bmi Callout 2 bounds=(0 18.5 25 30 50)Callout 3 /
         noavalue nobvalue
         target=. colors=(blue,green,yellow,red) Callout 4
         name="c:	emp&gname" Callout 5;
run;
quit;
%mend slider;

Callout 2 The indicator value, which determines the length of the horizontal line, is passed into the macro and is treated as a constant in the GKPI procedure.

Callout 3 The value range endpoints are specified. These will set the zones for the colors Callout 4 as well as the placement of the ACTUAL= and TARGET= values.

Callout 4 The colors of the individual segments are specified. In this example these are constants, but they too could be declared using macro parameters.

Callout 5 The NAME= option names the file that will contain the individual indicators.

We would like to report on each subject’s body mass index, BMI, value. In that report we need to show the indicator calculated for each specific subject. This means that we need to run the GKPI procedure once for each subject in the data set after first calculating the BMI value. The CALL EXECUTE routine allows us to create a series of macro calls; one for each observation in the DATA step.

title;
ods html file="c:	empslider.gif"; Callout 6
data bmi(keep=subject ht wt gname bmi);
   set advrpt.demog(obs=8); 
   length gname $4;
   bmi = wt / (ht*ht) * 703; Callout 7
   gname=cats('G',subject); Callout 8
   call execute('%slider('||gname||','||put(bmi,4.1)||')'), Callout 9
   run;
ods html close;

Callout 6 It is necessary to have an ODS destination open. We will not use this GIF file, but it will also contain the individual indicators.

Callout 7 The BMI value is calculated.

Callout 8 The subject number will become a part of the name of the file that contains the indicator that will be imported by PROC REPORT.

%slider(G200,24.3)
%slider(G201,21.4)
%slider(G202,25.1)
%slider(G203,36.5)
%slider(G204,18.0)
%slider(G205,25.1)
%slider(G206,23.0)
%slider(G207,24.3)

Callout 9 The CALL EXECUTE routine is used to build a series of macro calls—one for each incoming observation. The macro %SLIDER is passed the parameters needed for each specific subject (the subject number and the associated BMI value). This is sufficient information for PROC GKPI to generate the subject specific indicator.

After all the calls to the macro %SLIDER have been executed, a series of PNG files will have been generated Callout 5. These files have been named Callout 9 so that they can be imported by PROC REPORT Callout 10 in the correct order.

ods pdf file="&path
esultsE10_2_4.pdf" style=default;
title font=arial '10.2.4 Using GKPI';
proc report data=bmi nowd;
column subject gname ht wt bmi slider;
. . . . code not shown . . . .
define slider / computed ' ';
compute slider/char length=62;
slider=' ';
imgfile = "style={postimage='c:	emp"||trim(left(gname))||".png'}";
call define ('slider','style',imgfile); Callout 10
endcomp;
run;
ods pdf close;

Callout 10 The REPORT step creates a computed report item (SLIDER) that will hold the indicator image. The temporary variable IMGFILE contains the pointer to the PNG file Callout 5 that contains the image. For subject 200, IMGFILE contains: style={postimage='c: emp G200.png'}.

A portion of the resultant PDF file is shown here.

image shown here

10.3 PROC FREQ Graphics

The FREQ procedure has now been included in the list of base procedures that can produce graphics through the ODS Statistical Graphics routines. The TABLE statement supports the PLOT= option, which can be used to generate a number of graphs.

A number of different types of plots are available, especially if you are calculating test statistics, such as those generated with the CHISQ option. The PLOTS= option is used to make the plot requests. You may specify specific types of plots, as is done below, or you may request all plots (plots=all).

image shown here

ods graphics on;
ods pdf file="&path
esultsE10_3.pdf";
proc freq data=advrpt.demog;
   table wt / plots=cumfreqplot(scale=freq); Callout 1
   table sex*race/plots=freqplot(scale=percent); Callout 2
   run;
ods pdf close;

Callout 1 The CUMFREQPLOT can be used to generate frequency and cumulative frequency histograms. There are a number of modifier options that further refine the plot requests. Here we specifically request that the vertical axis be frequencies.

image shown here

Callout 2 For two-way tables we often need to see the relationship between the frequencies of the combinations of values. In this plot request we ask for a frequency plot of the relationship between the RACE and SEX. The plot request has been modified to have the vertical axes show percentages.

image shown here

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset