Return to UOCC HomeComputing News Home
Header bar

SAS-PC Version 8 offers Increased Graphical Capability

SAS 8's improved graphical features offer you the chance to use one system for both data analyses and graphical presentations

GOPTIONS | SYMBOL | AXIS1 and AXIS2 | GIF Files |

Robin High
robinh@darkwing.uoregon.edu

Visual displays of data are one of the most necessary and important components of data analysis.

Previous versions of SAS had rather limited graphical capabilities: you could make crude scatterplots with PROC PLOT, charts with PROC CHART, or histograms and boxplots with PROC UNIVARIATE. These visual aids are still available in Version 8 and are relatively easy to create. They certainly give excellent insights into the nature of your data by showing the "center" and "spread" of continuous data across levels of a categorical variable, or by showing how two or more continuous variables relate to each other, but the output is generally not of adequate quality for publications. SAS GRAPH has also been available to create publication quality visual aids, but it was cumbersome and difficult to use on Darkwing or Oregon.

One way to overcome these limitations was to save the data to be graphed to a text file, and then read that file into a specialized graphics program or a spreadsheet program (such as EXCEL) to create visual displays or to enter the data directly from a computer printout.

While the task of creating high-quality graphics in SAS is still demanding, Version 8 for the PC offers superior capabilities. It is well worth the time and effort required to become acquainted with its graphical features, especially if you already use PC-SAS for other applications and want to have one system for both data analysis and graphical presentations. If you already use SAS on Darkwing or Oregon, you should investigate its capabilities.

As you read this article, it will be helpful to see several examples of programs and their associated displays of what SAS GRAPH is able to create, particularly with the GPLOT procedure, by going to http://www.sas.com/service/techsup/sample/sample_graph.html

This site shows many features (and more) that I will introduce in this article. In particular, it shows many key statements and types of displays available that are not possible to present here.

Names of the graphical procedures in SAS GRAPH usually begin with the letter "G." That is, instead of using PROC PLOT to make a list file containing a scatterplot, you'll now apply the more sophisticated PROC GPLOT. One notable exception is a new procedure called BOXPLOT (now available in Version 8) that produces the same high- quality graphics as these "G" programs.

GOPTIONS [top]

The first step is to become familiar with the GOPTIONS statement, which performs a function similar to the OPTIONS statement you have probably already used when writing SAS programs. The purpose of the GOPTIONS statement is to apply levels of specific options to graphs created in the session or to override specific default values. It can be located anywhere within your SAS program; however, in order for the requested options to be applied to it, it must be placed before the graphics procedure.

Most options can be listed in any order in a GOPTIONS statement. One exception is the RESET=<> option that performs the function of restoring all or specific types of graphics options to their default values. When it is used, always place it as the first option immediately following the GOPTIONS key word.

Graphics options are cumulative; the value of any given option remains in effect until it is explicitly changed. When you enter additional GOPTIONS statements, the graphic options already selected remain in effect. All options return to their default values when apply the RESET=all option or exit SAS completely and start a new session.

To reset a specific option to its default value, submit the name of the option without a value after the = sign (i.e., a null graphics option) such as Htext= or Ftext= in the GOPTIONS statement.

The following GOPTIONS statement first resets all graphic options to their default values, and then specifies several desired qualities of a graph including text font, units of measurement, background color, and no printed border:

GOPTIONS RESET=all Ftext=swissb gunit=pct Cback=white NOborder ;

These options and many more are explained in the Graphics Options and Device Parameters Dictionary, which provides a complete description of how to use them. You can find these descriptions at http://sas.uoregon.edu/sashtml/gref/z0713550.htm

SYMBOL [top]

SYMBOL statements define the characteristics of plotting symbols used by PROC GPLOT. They create definitions used to control:

When you create new SYMBOL definitions, they are automatically applied to the next graph created by the GPLOT procedure. If you do not create SYMBOL definitions, GPLOT will use default values and apply them as needed. SAS also allows you to overlay plots of two or more variables on the same graph. When this is done you will need to use separate SYMBOL statements for each variable indexed by a number. For example, to plot the first variable, SYMBOL statement number 1 will be defined as

SYMBOL1 value=star height=2;

In this statement, note that:

For more information about the SYMBOL statement, see http://sas.uoregon.edu/sashtml/gref/zbolchap.htm#z0751130

Example
To show how these two statements work together to produce a graph with PROC GPLOT, GOPTIONS, and SYMBOL1 statements will now be applied to create a scatterplot for two quantitative variables, height (y) and weight (x). Several features of SAS are shown here that could be applied in other ways, but only one approach is shown here:

GOPTIONS RESET=all Ftext=swissb gunit=pct Cback=white NOborder

ROTATE=landscape PAPERSIZE=(11,8.5) TARGETDEVICE=hpljs2
Horigin=1.5 in Vorigin=1.5 in Hsize=8 in Vsize=5 in ;
SYMBOL1 value=star height=2;

PROC GPLOT DATA=measurements;
PLOT y*x / haxis=axis1 vaxis=axis2;
AXIS1 COLOR=black LABEL=(c=black h=3 "Weight (Pounds)")

WIDTH=2 MINOR=none ORDER=(20 30 40 50 60 70 80 90 100)
VALUE=(COLOR=black HEIGHT=2
'20' ' ' '40' ' ' '60' ' ' '80' ' ' '100');

AXIS2 COLOR=black LABEL=(COLOR=black HEIGHT=3 "Height (Inches)")

WIDTH=2 MINOR=none ORDER=(0 to 100 by 10)
VALUE=(COLOR=black HEIGHT=2
'00' ' ' '20' ' ' '40' '50' '60' ' ' '80' ' ' '100' );

TITLE1 Height=5 "Height vs Weight";
TITLE2 Height=3 "Scatter Plot of Data";
 

This SAS program demonstrates a useful programming convention: place the keywords that SAS expects in capital letters; place the options you specify in lower case letters. The graphical output of this procedure is shown in Figure 1 on the following page.

The first SAS statement (PROC GPLOT DATA=measurements;) invokes the plot procedure to create a scatter plot. The specific SASdata set used is called measurements. If no data set is specified, SAS uses the most recently created one:

PLOT y*x / <options>;

The PLOT statement tells SAS which numerical variables to plot. Variable y (height) is placed on the vertical axis and variable x (weight) on the horizontal axis. Note that the PLOT statement request two options that call for the horizontal axis to be specified by HAXIS=axis1 and the vertical axis specified by VAXIS=axis2 (both statements are defined next).

AXIS1 and AXIS2 [top]

These two statements allow you to define, in great detail, the structure and format of both the horizontal and vertical axes--including labels, range of data values, fonts, weights, and values plotted at the major and minor tick marks. The options from the previous PLOT statement specify which axis statement is assigned to the vertical axis (VAXIS=axis1) and to the horizontal axis (HAXIS=axis2).

One potentially nice feature of these two statements is that the sample program above shows how you can write distinct values as needed for the tick marks on each axis without necessarily being required to use numbers or equally spaced values.

You can also include options in the SYMBOL1 statement used above to superimpose a linear regression line with 99% confidence limits for the predicted values:

SYMBOL1 value=star height=2

These short examples demonstrate how with just a few statements you can literally "program" a graph to the exact specifications required for your document. Other useful statements include FOOTNOTE, PATTERN, and FORMAT. You can also annotate the graph with special text created in a DATA step and then applied with the annotate option.

Produce GIF Graphics Files for Your Documents [top]

Using SAS Graph to print a graph directly to a printer is often tricky. It's difficult to fit the graph on the page because you need to specify exact values for several options. One way of getting over this hurdle is to create gif files of the graphs. The gif format is more flexible, and you can easily adjust the layout of the document so that the graph will print out exactly as you wish.

To do this, you will need to add the device=<> option to a GOPTIONS statement. Inserting a two other statements as shown below, PROC GPLOT will produce a file called gplot.gif that contains a picture of your graph. You can then insert it directly into a Word document, making it much easier to adjust the size and layout of the graph on the printed page.

GOPTIONS device=gif; * include the option to create a gif file;

* open the html destination to send the file;
ODS HTML path="c:\d\sas\graph" body="plot_exmp.html";

PROC GPLOT DATA=measurements;
< insert SAS GPLOT statements >
RUN;

ODS HTML close; * close the html destination ;
RUN;

To read more details on how to make this process work, you can download an annotated example of this program from
http://www.uoregon.edu/~robinh/120_graph.html

Figure 1. A scatterplot for two quantitative variables, height (y) and weight (x), created by using PROC GPLOT, GOPTIONS, and SYMBOL1 statements.


Spring 2001 Computing News | Computing Center Home Page