This document outlines the use of SAS/Graph on all platforms that run SAS software. System-specific examples and discussions are of SAS in the UNIX environment are found in "SAS Under UNIX" at:
http://www.usc.edu/its/doc/statistics/sas/sasunix/
With all SAS/Graph PROCedures there are a number of options that will allow you to design colorful patterns and displays in graphic form. Through the use of titles and footnotes you can fully define the nature of your data. In addition, with the wide range of options for choice of colors, type fonts, height of your text, and angle to draw lines of text, etc., you can tailor a display to meet your own needs.
Graphics catalogs are special members of a SAS data base, but unlike a SAS data file they do not contain any observations or variables. They are graphics images saved in a file by a graphics procedure through the use of the GOUT= option. These images can be redisplayed by using the PROC GREPLAY in SAS.
Templates are utility members of a SAS data base. They allow the display of up to 5 graphics images on a single page. Templates are used in PROC GREPLAY, along with graphics catalogs, and consist of five panels. Each panel includes 4 sets of coordinates of a box which will border a graph, an angle by which the image is displayed, and a translate value which indicates the offset from the base of the display, coordinates (0,0), where the image will be displayed.
For more information on graphics catalogs and templates please refer to the References listed at the end of this document.
SAS/Graphs generated in Windows or Macintosh can be printed directly from the Graphics window (if an appropriate printer is attached, as is the case in our user rooms) by clicking File>Print in the Graphics window, when the graph is displayed.
In any operating system, SAS/Graphs can be saved to
a file (called a 'Graphics Stream File', or GSF)
and printed later.
This is the recommended method for printing SAS/Graphs
in UNIX.
The GSF is created by certain specifications in the
GOPTIONS statement (as outlined below), including a
driver (the GDEVICE= parameter) that is appropriate for
the printer that ultimately will be used.
The file into which the GSF is written is set up
using a FILENAME statement before the graph itself is generated.
The resulting file is then sent to
the printer or plotter with the usual print commands or
utilities for the system you are using (for example,
lpr can be used in UNIX.)
This document will focus on using SAS/Graph interactively. In general, the same programs submitted interactively may be submitted in batch with the same results. (In batch processing, SAS statements and external file references are written into a file, and then run by specifying the SAS command followed by that file's name.)
The ITS documents about SAS on the specific platforms (SAS Under UNIX, or SAS for Microcomputers, as noted above) have details on how to run SAS/GRAPH interactively on those platforms.
GOPTIONS DEVICE=XCOLOR;
Normally, no specification is necessary as the default will be set correctly. If you are running X-Windows on a monochrome terminal, you can change the driver to XBW (Black-and-White) or XGRAY (Grayscale).
For more information about using X-Windows in general, see the ITS Help System at
http://www.usc.edu/its/doc/and for more information about running SAS in X mode, see the "SAS Under UNIX" document at:
http://www.usc.edu/its/doc/statistics/sas/sasunix/
http://www.usc.edu/its/software/
To obtain X-windowing software that is not distributed by ITS, you must purchase it from an outside vendor.
(Of course, SAS/GRAPH running under Windows or Macintosh, not on UNIX, needs no special software to display the graphs at the monitor.)
If you wish to output a graph on any ITS-supported printer and you're using SAS for UNIX, a Graphics Stream File will be essential, even if no transfer to another operating system is anticipated. (Patrons using SAS for Macintosh or SAS for Windows have the option of printing graphs directly from the Graphics window by clicking File>Print; this method isn't recommended for UNIX SAS/Graph.) Most ITS printers accept PostScript files, and special drivers have been set up in the UNIX environment for PostScript use. These drivers are listed and documented below, as is the procedure for creating and sending a PostScript Graphics Stream File to an ITS printer from a UNIX session.
GSFs are created by specifying the appropriate output device
driver to the
DEVICE= parameter of the GOPTIONS statement (the
GOPTIONS statement is discussed
below) and by directing the output of the batch or
interactive job to a file, rather than to a screen or other
hardcopy device.
The ITS documentation on SAS in each operating
system has examples and instructions.
This documentation can be found at:
For full details on creating Graphics Stream Files see the SAS/Graph manuals listed in the References section at the end of this document. For more information on the GOPTIONS statement, see below, and the References.
In summary, to generate a graph in interactive SAS to be printed at a PostScript printer from a UNIX SAS/Graph session, write a program that includes a FILENAME statement that points to a file to hold the PostScript output, and a GOPTIONS statement as in the following example:
FILENAME NICKNAME '<--file specifications for UNIX, Mac or PC-->';
GOPTIONS RESET=ALL DEVICE=PSUSCSM GSFNAME=NICKNAME
GSFLEN=80 HSIZE=7 VSIZE=9 BORDER NOPROMPT;
data temp; input a b;
cards;
56 87
56 89
57 89
57 90
57 91
58 92
68 94
79 98
;
title1 f=duplex c=green 'This is my test graph';
symbol1 c=red i=join v=star;
proc gplot; plot a*b;
run;
HSIZE=, VSIZE= and BORDER parameters are
optional. Note also that some GOPTIONS may differ from system to
system; the ITS Help documentation for SAS in each system has more
specific examples. The graph in the example above will be 7"
wide, 9" tall, and will have a border around the entire area.It is also possible, of course, to send Graphics Stream Files to printers other than those known to the system you are using to generate the graphs -- indeed, virtually any printer anywhere -- and to create GSFs in systems other than UNIX, Windows or Macintosh. When generating a graph that is to be transferred for printing to a system other than the one on which it was generated, keep in mind that the file containing the graph output must be sent in BINARY mode in whatever file transfer process you use. Also, the outside printer will have certain requirements for the format (usually PostScript, but this varies) and the medium (diskette, tape, ftp, etc.) used for the file that is to be printed as a graph.
USC's
Print Center
at the Bookstore
is an example of an outside place to print graphs
generated by SAS.
They have color printers up to 11"x14" which
will print graphs encoded in PostScript, using the drivers
described in this document (e.g., PSUSCSM and
PSUSCLG). Please note, however, that it is strongly recommended
that you test your graph output on cheap, monochrome printers
such as ps_lvlg40, as many outside printing establishments
can be expensive.
For a list of printers like ps_lvlg40 that your account can access,
type printers at your UNIX prompt.
The syntax of the GOPTIONS statement is,
GOPTIONS <option> = <specification[s]> ;
In general, the GOPTIONS statement gives SAS the information it needs to create an output stream (or output file) appropriate for the device on which the graph will appear. Since you will need to use a device driver appropriate to the device on which you intend to see your graph, you will need to choose from among the many available drivers. You can see all the available graphics device drivers online by running PROC GDEVICE in interactive SAS. (This PROC is not available in batch mode.) Invoke SAS at the UNIX prompt or launch SAS for Macintosh or SAS for Windows, type the following program in the PROGRAM EDITOR
proc gdevice;
run;
and then submit the program. SAS will put up a temporary GDEVICES window, in which you can scroll down and up, and find the graphics driver name most suitable for your chosen output device.
There are many parameters available on the GOPTIONS statement. Some are already coded into the driver itself (though you can override them if necessary). Other basic parameters that the user must code are discussed here. For more information about GOPTIONS parameters, see References below.
The most important GOPTIONS parameter is DEVICE=,
since this
tells SAS how to structure and code the actual language that will
create the graph at the printer. SAS/Graph drivers can be used
as they are supplied by the Institute, or they can be modified.
Most graphs intended to be printed at ITS are output to
PostScript devices such as
Driver max size printername orientation
-----------------------------------------------------------------
PSUSCMAX 32"x100" (must use non-ITS printer) portrait
PSUSCLG 11"x17" (must use non-ITS printer) portrait
PSUSCSM 7.5"x10" (ps_lvlg40, etc.; see NOTES) portrait
(on 8.5"x11"
paper)
-----------------------------------------------------------------
ps_lvlg40 (an 8-1/2x11" monochrome
printer in Leavey Library; this printer name is used only as an
example; there are many others; type
printers at your UNIX prompt for a complete list).
SAS provides several drivers for PostScript output,
and ITS has supplied three additional drivers modified for use
with PostScript printers. The available ITS-modified drivers
are:
NOTES:
GSFMODE=REPLACE,
GSFLEN=80, GPROLOG='25210D0A'x (or the equivalent),
and GACCESS=SASGAEDT. These, and all
defaults, can be overridden if necessary.HSIZE= and/or
VSIZE= parameters in
a GOPTIONS statement), you have a number of alternatives. You
can make the VSIZE smaller than the HSIZE, in which case your
graph will appear to be landscape. You can actually change the
orientation by specifying
ROTATE=LANDSCAPE, in which case your
graph will be rotated 90 degrees from what it would have been
without the ROTATE= option, within whatever size dimensions are
in effect at the time. Note that
ROTATE= LANDSCAPE will not
always result in a truly "landscape" graph. It depends on the
dimensions being used. The rule of thumb is to first imagine
your graph in the given (max) dimensions, with the width (34")
being the bottom of the graph. Then change the dimensions
(and/or rotate the graph with
ROTATE=LANDSCAPE) to make your
graph appear in the proper aspect and the desired size.RESET=ALL, which resets
any previous GOPTIONS to default or null values;
NOPROMPT, which
tells SAS there is no need to prompt you when the graph is ready;
and GSFNAME=nickname, where "nickname" is
the name by which you
have allocated the file that will hold the Graphics Stream File.
(This is usually done in a FILENAME statment, hence the
"nickname" would be what SAS calls a FILEREF.)
Other GOPTIONS that you might use (not required) are
HSIZE= and VSIZE=,
which will set the overall dimensions of your graph
(within the maxima set by the driver);
BORDER, which draws a
border around the area in which the graph appears (titles,
footnotes and graph are all inside the border); and
ROTATE=LANDSCAPE, which will rotate
the graph 90 degrees from its
default orientation. (By default, the USC drivers are set to
portrait orientation, but, as explained in the NOTES following
the table above in which the driver names are listed, this only
means that when the default dimensions are in effect, the height
of the graph will be longer than the width. If you reduce the
height dimension so that it is shorter than the width, your graph
will appear in landscape mode without
ROTATE=LANDSCAPE. Think of
ROTATE as turning the graph 90 degrees from where it would have
otherwise been.)
A more recent development is SAS/GIS, or Geographical Information Systems software. GIS is an interactive environment in which maps can be drawn and manipulated with great flexibility. SAS/GIS is introduced later in this document.
PROC GMAP can be used to produce choropleth, surface, prism, and block maps. PROC GMAP requires a MAPS data set as well as a RESPONSE data set for input. This MAPS data set can be one the user has created or one of the MAPS data sets supplied by SAS. Therefore, if you want to use the MAPS data set provided by SAS, your LIBNAME statement would appear as follows:
LIBNAME MAPLIB '<--directory holding the maps files-->';
In UNIX systems: To see the maps that are available, type:
ls /usr/usc/sas/default/maps
Each map file has a descriptive name, followed by .ssd01
followed by .Z, which indicates that it is
compressed. For example, one map of El Salvador is named
salvador.ssd01.Z
To prepare this map file for your use, you would uncompress it
into /tmp space,
or into one of your own directories (for
example, ~/mymaps), as follows:
zcat /usr/usc/sas/default/maps/salvador.ssd01.Z >
~/mymaps/salvador.ssd01
(The two lines above are actually a single command, to be typed on one line at your UNIX prompt.)
Note that it doesn't matter what you call your copy of the file,
but you must have the extension .ssd01 for it to work.
In SAS for Windows or Macintosh: To see the maps that are available, find the directory they are in by clicking Globals>Access>Display Libraries, then type an 'S' (select) to the left of the MAPS libname. This will display a list of all the files in that library, i.e., all the available maps data sets.
You cannot tell from the file name whether the files are compressed, so if you don't otherwise know, you can run the Map Data Sets Utility which will tell you if the Map Data Sets are compressed and give you the option of uncompressing them. To run this utility, click Help>Utility then choose the SAS/GRAPH Maps Data Set Utility.
libname maplib '~/mymaps'; /*<--this is a UNIX example */
libname maplib 'c:\saswin\maps'; /*<--this is a Windows example */
libname maplib 'SAS:Maps'; /*<--this is a Macintosh example */
proc gmap data=<your SAS data set> map=maplib.salvador;
NOTE: In Public User Rooms, the maps will be on a network server drive; for details, see the SAS for Microcomputers document at:
A PROC that uses the maps, then, could make use of the same LIBREF and would specify the SAS data set containing an Africa map as follows:
proc gmap data=<your SAS data set> map=maplib.africa;
A response data set is a SAS data set that contains, for each unit area, one or more reponses to be mapped. For example, if you were interested in the number of elementary schools in each state of the U.S., the response data set might contain the number of schools in each unit area (in this case the unit area would be STATES), and the MAPS data set would be the U.S. In addition, you would need one or more ID variables that would uniquely define the unit area. In the example above the ID variable would be STATES. Thus, PROC GMAP would look as follows:
proc gmap data=schools map=maplib.us; id states;
Notes and sample programs for SAS/GIS and other SAS mapping techniques are available on the SAS/GRAPH frequently asked questions (FAQ) page at:
http://www.usc.edu/its/doc/statistics/sas/faqgraph
To invoke SAS/GIS for routine use, either click Globals>Present>SAS/GIS, then File>Import; or run the following command:
Command==> gis then click File>Import to get the Frame where you can specify the location and names of your map and spatial data files.
Details about using the SAS/GIS Import windows and other features are in the SAS/GIS Software Usage and Reference manual. This manual, and the other basic SAS Reference Guides, are available in the manual racks in the Waite Phillips Hall User Area.
To create a map from the TIGER files provided by SAS:
AF C=SASHELP.GISIMP.TIGERCD.FRAME
NOTE: If you don't have a Command Line, or don't know where one is, you can click Globals>Options>Command Line to request one.
This opens a SAS "Frame" called the SAS/GIS Map Extraction Utility Window in which you will be prompted to enter the path to your 'Tiger CD-ROM' (this terminology is used in the UNIX environment and on the User Rooms Windows machines as well, even though no CD-ROM is needed there). If you are using SAS for Windows or Macintosh on a system installed and/or maintained by you, do as requested by the message SAS gives you.
/usr/usc/sas/default/TGRMAPS
In SAS for Windows in the ITS User Areas, enter:
g:\programs\stat\saswin\TGRMAPS
Note that, apparently, SAS regards this path as case sensitive, so TGRMAPS must be all caps.
If you do want your map files (or some of them) to be saved permanently, you can choose SASUSER for the LIBRARY field or you can use any LIBREF that you have already created (prior to your SAS/GIS session) using a LIBNAME statement.
The TIGER maps referenced above are specially compressed and processed by SAS for use with SAS/GIS through the "TigerCD" Frame. For this reason, they can be accessed only by the AF command as shown above, which calls a special access Frame. Of course, any appropriate GIS-type maps and data, including the original TIGER files distributed by the Census Bureau, can be imported into SAS/GIS using the usual File>Import menu choices within SAS/GIS.
The ATLAS files are raw data coordinates, along with Census Tract identifying numbers, but some processing is necessary before SAS (or any other software) can make a map from these coordinate numbers.
To see a list of the ATLAS files, enter the following command in an RCF UNIX session:
ls ~datastor/census/atlas90
or visit the following Web page:
www-rcf.usc.edu/~datastor/census/atlas90/
Each file is named with the format ATLAS90.xxxT,
where "xxx"
is a three-character abbreviation of the county represented in that
file.
For example, ATLAS90.LOST (!) is the file for Los Angeles County.
In addition, the census/atlas90 directory has two files pertinent to the Atlas files and Census Tract boundaries in general. CT708090.CORRESP contains details about the changes in Census Tract boundaries over the last three censuses. CT708090.DATA contains aggregated raw data such as total population, population by certain ethnicities, population by age categories, marital status and so forth. NOTE: all the file names in the census/atlas90 directory are UPPER CASE as shown in the examples, while the directory itself remains lower case.
The VKC (Applied Social Sciences) Library has a 10-page "code book" that outlines the contents of all the ATLAS90 files.
Each ATLAS file contains X and Y map coordinates for each Census Tract
in the county, beginning with a "title line" that
contains the State, County and Census Tract numbers and other
information.
As an illustration, the first few lines of
data in ATLAS90.LOST for Census Tract 1011 look like:
"060371011.00",91
-118.302500,34.273900
-118.301500,34.274200
-118.301083,34.274425
-118.300200,34.274900
-118.298900,34.275200
-118.298600,34.275400
(etc.)
06), the County Code
(037), and the Census Tract number
(1011.00), followed (after the last double quote)
by a number representing the number of coordinates listed
for that tract.
Each line after the "title line" contains two
numbers, separated by a comma.
These are the X and Y coordinates for drawing the
boundaries for that particular Census Tract.ITS provides a sample program for reading in the Atlas coordinate data and mapping the Census Tracts using SAS/GRAPH. The same SAS data set created in this program can be imported into SAS/GIS as a GENPOLY (Generic POLYgon) file. The complete sample program is in:
http://www.usc.edu/its/doc/statistics/help/census/programs/atlasmap1.sas
and the elements of that program are explained here.
The graph that results from the program can be viewed at:
http://www.usc.edu/its/doc/statistics/help/census/miscellaneous/atlas.gif
Reading the Coordinates into a SAS Data Set.
The sample program makes a "permanent" SAS data set
in the /tmp area, as shown in the following
LIBNAME statement.
This can be specified anywhere you like, or you can use
temporary SAS data sets for this operation, if you prefer.
The raw data are stored on the RCF, and are specified in the sample
program using the following FILENAME statement:
libname atlasdta '/tmp/';
filename inatlas '~userserv/public_html/census/atlas90/ATLAS90.LOST';
The first step in mapping the coordinates found in the ATLAS files is to create a SAS data set with the following variables:
TRACT X Y
Although the STATE, COUNTY and COORDNUM variables are not necessary for basic maps, since they are present in the data, they are read in by this sample program.
/*** THESE FIRST LINES GIVE SAS THE LIST OF DESIRED TRACTS ***/
%let traclist=%str(
2218,2219,2226,2227,2246,2247,2311,2312
);
/*** THIS IS THE MAIN DATA STEP TO CREATE THE SAS DATA SET ***/
data atlasdta.atlas1; infile inatlas; keep tract coordnum x y;
retain state county tract coordnum;
input @1 test $1. @;
if test='"' then do; state=.; county=.; tract=.; coordnum=.;
input @2 state 2. @4 county 3. @7 tract 4. @16 coordnum 2.; end;
else input @1 x 11. @13 y;
format x y 12.6;
if x=. and y=. then delete;
if tract in (&traclist.);
In the program above, the list of Census Tract numbers is assigned
to a "symbolic variable" called traclist
in the %LET statement, and then used in the later
IF statement as &traclist.
Annotating the Map with Customized Labels. The use of Annotate data sets in SAS/GRAPH is a difficult, but ultimately rewarding process, as it allows nearly complete flexibility in labeling a graph to your specifications. The sample program contains an annotate data set that adds labels to the map, but since using the Annotate facility is relatively complex, the details are left to the SAS/GRAPH documentation, which you should consult if you are interested.
The annotations used in the sample program for this particular map places the text 'USC Campus', a palm-tree symbol, and the Census-Tract numbers in the appropriate places on the map surface. The SAS code for the Annotate DATA step looks like this:
data atanno; length text $ 9 hsys xsys ysys $ 1;
input style $ hsys $ xsys $ ysys $ function $ text $ x y size;
cards;
cartog 1 1 1 label L 45 50 6
centb 1 1 1 label USC 45 45 4
centb 1 1 1 label Campus 44 40 4
centb 1 1 1 label 2218 29 91 4
centb 1 1 1 label 2219 29 75 4
centb 1 1 1 label 2226 12 52 4
centb 1 1 1 label 2227 34 53 4
centb 1 1 1 label 2246 79 54 4
centb 1 1 1 label 2247 56 73 4
centb 1 1 1 label 2312 25 17 4
centb 1 1 1 label 2311 64 23 4
;
Once the Annotate data set (ATANNO) is created, it is then
referenced using the ANNO= option of the
PROC GMAP statement, as shown in the next
section.Creating the Map of the Census Tracts. You are now ready to create the map itself. This is done with a PROC GMAP statement with an appropriate CHORO statement, as shown in the following portion of the sample program:
pattern1 value=mempty repeat=5000;
proc gmap map=atlasdta.atlas1 data=atlasdta.atlas1 anno=atanno;
title1 h=2 f=centb 'Census Tracts in USC Neighborhood';
title2 h=1.5 f=centb 'Los Angeles, California';
footnote1 h=1.3 f=centb 'Source: 1990 Census ATLAS files';
id tract; choro tract / discrete nolegend coutline=black;
Many of the statements and features in this sample are optional,
including the TITLE and FOOTNOTE
statements.
The PATTERN statement assures that each of the
Census Tract areas will be empty; otherwise, SAS will fill them with
patterns.
The display of the map is automatic, unless you are directing the map information to a Graphics Stream File (GSF) for later printing and/or saving. See the SAS/GRAPH User's Guide and the ITS online information on SAS/GRAPH at
http://www.usc.edu/its/doc/statistics/sas/
for more information on how to use GSFs.
Current schedules for User Services Classes (also called "Hands-On Workshops") are listed on the Web at:
http://www.usc.edu/libraries/adventures/Any Statistics Software class can be taught when groups of five or more users request them. Other ITS Classes by special arrangement may require a minimum of 10 attendees. Classrooms must be arranged by those requesting the class. Contact the User Services office for details, or visit
www.usc.edu/its/doc/statistics/help/classes/requests.shtml
Reference 1. Complete online documentation.
Reference 2. The basic reference for SAS/Graph.
Reference 3. Geographical Information Systems reference.
Reference 4. Basic reference manual for SAS.
Documents listed here can be obtained from :
Consulting. The ITS Consultants may be familiar with the language and general operations of this software, but it may be necessary to make an appointment with a member of the full time staff in order to receive detailed help. Support of statistics software is the responsibility of the ITS Statistics Consultant with the participation of other full-time ITS staff. These people may be contacted through the ITS Customer Support Center as shown here.
Customer Support. USC students, staff or faculty who would like information about ITS Workshops or about obtaining site-licensed software or other computing-related questions should visit the Customer Support Center in Leavey Library Lower Commons, or call 213.740.5555, or send eMail to <consult@usc.edu>
Documentation. This document, and many others on a variety of topics, are available in the ITS Customer Support Help System, available on the World Wide Web at:
http://www.usc.edu/its/
You can find Statistics Software Help Documents through the search engine at this same URL, or go directly to them at:
http://www.usc.edu/its/doc/statistics/help/
Newsgroups. Another source of information, this one providing the opportunity to exchange thoughts with other users, is the newsgroup 'usc.comp.all.stat.users'. For more information about reading news, subscribing to newsgroups, and related topics, visit
http://www.usc.edu/its/doc/internet/news/