Elements of a SAS/GRAPH Program |
Most SAS/GRAPH programs have Base SAS statements, ODS statements, and SAS/GRAPH statements. Annotate DATA steps and DSGI functions are also used in many SAS/GRAPH programs. The sample program below identifies the basic parts of a typical SAS/GRAPH program. Each element is described in more detail in the following sections.
SAS/GRAPH PROC Step |
A group of SAS procedure statements is called a PROC step. The PROC step consists of all the statements, variables, and options that are contained within the (beginning) PROC and (ending) RUN statements of a procedure. These statements can identify and analyze the data in SAS data sets, generate the graphics output, control the appearance of the output, define variables, and perform other operations on your data. You can also specify global statements and options within the PROC step to customize the appearance of your graph, but it is often more efficient to specify global statements before the PROC step.
The procedure statement identifies which procedure you are invoking (for example, GCHART, GMAP, or GCONTOUR) and identifies which input data set is to be used.
Subordinate statements are statements used within the procedure that perform the work of the procedure. Subordinate statements that generate graphs are called action statements. At least one action statement is required for a procedure to produce a graph. Examples of action statements are the HBAR statement in the GCHART procedure and the BUBBLE statement in the GPLOT procedure.
Non-action statements are those that do not generate graphs. The GRID statement in PROC G3GRID and the DELETE statement in PROC GDEVICE are examples of non-action statements.
There are many options that you can specify within the PROC step to control your graphics output. PROC step options always follow the forward slash (/) following the action statement of the procedure. These options might control such things as axis characteristics, midpoint values, statistics, catalog entry descriptions, or appearance elements of your graph. For example, the SUBGROUP= option in the BLOCK statement of the GCHART procedure tells the procedure to divide the graph's bars into segments according to the values of the SUBGROUP= variable. The HAXIS option in the PLOT statement of the GPLOT procedure, as shown in Typical SAS/GRAPH Program, specifies where to draw the major tick mark values for the horizontal axis.
Global Statements |
A global statement is a statement that you can specify anywhere in a SAS program. Global statements set values and attributes for all the output created from that point in the program when the statement is specified. The specifications in a global statement are not confined to the output generated by any one procedure but apply to all the output generated then point on in the program, unless they are overridden by a procedure option or another global statement. The RESET= option in the GOPTIONS statement also overrides global statements by resetting them.
Below is a list of all the SAS/GRAPH statements along with a brief description of each. See SAS/GRAPH Statements for a more detailed description of each of these statements.
modifies the appearance, position, and range of values of axes in charts and plots.
processes data and orders output according to the values of a classification (BY) variable. The BY statement in SAS/GRAPH is essentially the same as the BY statement in Base SAS, but the effect on the output is different when it is used withSAS/GRAPH procedures. When used with SAS/GRAPH procedures, the BY statement subsets the data and creates a graph for each unique value of the BY-variable.
Note: The BY statement is an exception here because it is not a global statement. It must be specified within a DATA or PROC step.
specifies graphics options that control the appearance of graphics elements by specifying characteristics such as default colors, fill patterns, fonts, or text height. Graphics options can also temporarily change device settings.
modifies the appearance and position of legends generated by procedures that produce charts, plots, and maps.
defines the characteristics of patterns used in graphs created by the GAREABAR, GBARLINE, GCHART, GCONTOUR, GMAP, and GPLOT procedures.
defines the characteristics of symbols that display the data plotted by a PLOT statement used by PROC GBARLINE, PROC GCONTOUR, and PROC GPLOT as well the interpolation method for plot data. The SYMBOL statement also controls the appearance of lines in contour plots.
add text to maps, plots, charts, and text slides. They control the content, appearance, and placement of text on your graph. The FOOTNOTE statement is used to display lines of text at the bottom of the page. The TITLE statement is used to specify up to ten title lines to be printed on the title area of the output. The NOTE statement is used to add text to the procedure output area of your graph.
Note: The NOTE statement is a local statement. It can be specified only within a PROC step, and it affects the output of that PROC step only.
Annotate DATA Set |
An Annotate DATA set is a data set containing graphics commands that can be applied to SAS/GRAPH output. See Using Annotate Data Sets for information on building and using Annotate data sets. The Annotate facility can be used to create a completely new graph or to annotate existing PROC output. See Annotate Dictionary for a complete description of all Annotate functions and variables. Below is an example of how the Annotate facility can be used to add text labels and symbols to a graph that was created using the GMAP procedure.
Using Annotate with GMAP Procedure Output
DSGI Functions and Routines in a DATA Step |
The DATA Step Graphics Interface (DSGI) enables you to create graphics output within the DATA step or from within an SCL application. Through DSGI, you can call the graphics routines used by SAS/GRAPH to generate a custom graph, or to rescale and replay existing graphs into viewports. DSGI GASK routines can be used to query current system or graphics area settings. For more information on DSGI functions and routines, see The DATA Step Graphics Interface.
ODS Statements |
Like Base SAS, SAS/GRAPH uses ODS destination statements ( , ) to control where the output goes and how it looks. While ODS statements are not required in every SAS/GRAPH program, they are necessary if you want to generate graphs for destinations other than the default listing destination. Some other destinations include HTML, RTF, and PDF. For more information about ODS destinations, see Understanding ODS Destinations in SAS Output Delivery System: User's Guide.
As shown in Typical SAS/GRAPH Program, the ODS destination statement is used at the beginning and end of the program to open and close the destination, respectively. If you do chose to use a destination other than the default and need to use the ODS destination statement, you should always open the destination before calling the procedure. To conserve system resources, you should also use the ODS destination statement to close the LISTING destination if you do not need LISTING output.
You can use the STYLE= option on the ODS destination statement to change the style that is applied to your output. For more information about the STYLE= option, see Controlling The Appearance of Your Graphs.
Base SAS Language Elements |
The following Base SAS language statements are also part of SAS/GRAPH:
assigns a format to a variable. SAS/GRAPH procedures use formatted values to determine such aspects of the graph as midpoints, axis labels, tick-mark values, and legend entries.
associates a SAS fileref with an external text file or output device. See FILENAME Statement for a more detailed description of this statement.
executes the statements in the PROC step.
assigns a descriptive text string (a "label") to a variable. The label appears in place of the variable name on the axis and legend.
associates a libref with a SAS library. See LIBNAME Statement for a more detailed description of this statement.
control the output of SAS/GRAPH procedures, where the output is sent (destination), the appearance of the output (STYLE=), and the output file type (DEVICE=). See Getting Started With SAS/GRAPH for information on using ODS with SAS/GRAPH procedures.
changes the value of one or more SAS system options.
executes any statements that have not executed and ends the procedure. It also ends a procedure that is using RUN-GROUP processing.
specifies observations from SAS data sets that meet a particular condition. You can use a WHERE statement to easily subset your data.
For a complete description of these statements, see Statements in SAS Language Reference: Dictionary.
The FILENAME statement associates a SAS fileref with an external text file or output device. With SAS/GRAPH software, you can use a FILENAME statement to to the following tasks:
point to a text file that you want to use for data input or output.
assign the destination of a graphics stream file (GSF). This destination can be either a single, specific file or an aggregate file storage location, such as directory or PDS. See Exporting Your Output for information on creating graphics stream files.
You can also use the FILENAME statement to route input to and from other devices. For details, see the SAS documentation for your operating environment.
A FILENAME statement that points to an external file has this general form:
FILENAME fileref 'external-file'; |
is any SAS name.
is the physical name of the external file or aggregate file storage location you want to reference. For details on specifying the physical names of external files, see the SAS documentation for your operating environment.
The LIBNAME statement associates a libref with a SAS library. A SAS library can be either temporary or permanent. Typically, SAS libraries used with SAS/GRAPH software contain the following items:
SAS files for data input and output.
SAS catalogs that contain SAS/GIS maps, fonts, GRSEG, CMAP, TEMPLATE, or device entries.
SAS catalogs that contain graphics output. These catalogs are often stored in permanent libraries. See Controlling Where Your Output is Stored for information on storing graphics output in a permanent catalog.
LIBNAME libref 'SAS-library'; |
is any SAS name.
is the physical name for the SAS library on your host system. For details on specifying SAS-library, see the SAS documentation for your operating environment.
Other Resources |
For more information on using and managing SAS/GRAPH programs to create graphics output, see Getting Started With SAS/GRAPH.
For more information on bringing SAS/GRAPH output to the Web, see Introducing SAS/GRAPH Output for the Web.
For information on using and managing SAS/GRAPH output, see SAS/GRAPH Output.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.