http://www.usc.edu/its/doc/statistics/sas/sasgraph/
If you are running SAS under X-Windows on a Sun workstation or
on a PC or Macintosh
running X-windowing software, SAS should display any graphs
you generate without requiring you to enter a
DEVICE= specification.
Contact the consultants (see the end of this document) for more
information about X-Windowing software that runs on a
PC or Macintosh.
Printing graphs from SAS is done in two ways: sending the graph
directly to a printer or routing the graph to a graphics stream
file (GSF) which is then sent to the printer via an lpr command.
The printers command at the UNIX prompt will show a list of
printers known to your system, to which you can print graphs
directly or send the GSFs via the lpr command.
(Of course,
GSFs also can be transferred to machines other than your system
which may have access to printers more convenient to you.) The
examples given here will show how to make a graph appropriate for
a PostScript printer, though there are many alternatives, as SAS
can output graphs to most printers on the market. The list of
printers shown by the
printers command designates PostScript
printers by starting the printer name with
ps_, such as
ps_ucc101, which will be used in the examples below.
To determine the appropriate graphics driver in SAS for the printer or plotter on which you will be printing or displaying your graph, invoke interactive SAS and submit the PROC GDEVICE statement. This will bring up a special window in which all drivers available in SAS are listed, along with a short description of the corresponding printer or plotter. You can scroll up or down and find the description and driver name that most closely matches your output hardware. This window includes drivers that have been customized by ITS for use with PostScript printers. (A list of the drivers customized by ITS is provided below.)
The following is a partial list of the GOPTIONS parameters that may be used in producing a graph from SAS under UNIX. Please note that there are many alternative ways in SAS to perform these same tasks, and what are presented here are only samples to get you started. For a complete discussion of these, and other, GOPTIONS see the relevant SAS manuals. (Some of these options are used for all graphs, some just for directly-printed ones, and some just for GSFs. The appropriate options are shown in the examples below.)
RESET=ALL
(resets previous goptions settings; this must be first)
DEVICE=devicename
(PostScript devices include PS, PSL, and so forth;
see the SAS/GRAPH manual for a more complete list, or
run PROC GDEVICE for the most complete list; ITS has
added some customized drivers for various sizes of
PostScript output; these drivers are PSUSCSM, PSUSCLG,
and PSUSCMAX: see below for details on these drivers)
GSFNAME=fileref
("fileref" is the nickname specified in the FILENAME
statement; this is used for GSFs)
GPROLOG='25210D0A'x
(this may be necessary to initialize Post Script printers
with the usual %!
characters; use this option only with PostScript output,
and only if the driver doesn't already supply it)
GSFLEN=80
(length of the GSF file's records; value may also be 132 when
graphs are being sent directly to a printer)
GSFMODE=REPLACE
(to replace previous graphs in the GSF; other options are
APPEND and PORT)
NOPROMPT
(this suppresses prompts that ask you to turn on a printer,
and so forth; if you see such a prompt, hit return)
To print a graph directly from SAS to a printer, first identify a
printer that is known to your machine (by using the printers
command) and convenient to you, note the name, and type it in the
program in the appropriate place.
One example is shown in (1)
below, using the ITS PostScript printer named ps_ucc101.
To create a file containing a graph that will be sent to a printer at a later time, code the proper statements and options for a Graphics Stream File (GSF). GSFs are files created by SAS using the driver appropriate for the printer which will ultimately receive the graph. To make a GSF that will print on a PostScript printer, you will need to use a FILENAME statement to set up the file to receive the GSF, and several GOPTIONS statements, as shown in example (2) below.
After the FILENAME and/or GOPTIONS statements, the graph can be
created as usual. If you are reading raw data before issuing the
graphics PROC, you will need a DATA step. If you are running the
graphics PROC against a SAS data set previously saved, you will
only need the graphics PROC with a DATA= option. In the examples
below, it is assumed you have your data in a SAS data set called
sasdata.plot14.
Example (1) -- Printing a Graph Directly to a Printer
filename mygraph pipe 'lpr -Pps_ucc101';
goptions reset=all device=psuscsm gsfmode=replace
gsfname=mygraph gsflen=80 noprompt;
proc gplot data=sasdata.plot14; plot var1*var2; run;
Example (2) -- Creating a Graphics Stream File for Later Printing
filename graph8 '~/sasprogs/graph1.ps';
goptions reset=all device=psuscsm gsfname=graph8
gsflen=80 gsfmode=replace noprompt;
proc gplot data=sasdata.plot14; plot var1*var2; run;
SAS sometimes behaves unpredictably when users alternate between color and monochrome graphs using the same SAS program, with different drivers plugged in. What was to be a dotted line will appear as such in a monochrome graph, but when a color terminal or plotter is used, the line may appear solid. This is because of a complex hierarchical default system regarding patterns, colors and such. To be sure that the graph will appear as you intended, you should specify all colors, patterns and other parameters explicitly, rather than leaving anything to SAS's defaults. Defaults will usually not disappoint you, but if you begin getting results other than what you expected, the solution often is to be explicit about every setting.
To send your graphs to a PostScript printer, you will need to
create a graphics stream file (see above) and you must set the
DEVICE= option to an appropriate driver. ITS has drivers
specially modified for standard PostScript printers or, if you
wish, you may create or modify your own graphics driver. (See
the SAS documentation for details on modifying or creating graphics device
drivers.) In addition, you may need to ftp your graphics stream
file to a system that knows about the printer you wish to use).
To see a list of printers known to a particular system, type
printers at that system prompt.
The drivers customized at USC for PostScript printers are:
driver max size printername
--------------------------------------------------------
PSUSCSM 7.5"x10" (various; e.g., ps_ucc101)
PSUSCLG 11"x17" (must use Graphics Stream File)
PSUSCMAX 34"x100" (must use Graphics Stream File)
GSFMODE=REPLACE, GSFLEN=80, and
GPROLOG='25210D0A'x.
ps_ucc101,
and is known to all systems. To see a
list of other printers known to the system where your SAS
program generated the graphics stream file (GSF), type
printers at the system prompt. If the printer you want
isn't in that list, ftp the GSF to a system that knows your
chosen printer, and lpr the file from there.
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.
Call the office or business which will be printing your graph, tell them you will have a graph encoded in PostScript, and ask what kind of file or diskette they will require. When you learn this information, you will then be able to download your file to a diskette, or transport it using the method that your printer requires.
The example below shows all the elements needed to make a
graphics stream file using one of the USC-modified drivers (in
this example, PSUSCSM). The GOPTIONS statement is typical, and
the
RESET=, DEVICE= and
NOPROMPT parameters should always be
included. The GSFNAME=
parameter must match the FILEREF on the
FILENAME statement (in this example GRAFOUT), and the optional
BORDER parameter puts a box around the graph. The optional
HSIZE= and
VSIZE= parameters resize the graph within the maxima
(which are 7.5" and 10",
respectively, for this particular driver).
filename grafout 'test1.graph';
goptions reset=all device=psusclg gsfname=grafout
hsize=6 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;
-P switch.
For example, if you have prepared
a graphics stream file (GSF) called graph.test
you can send it
to the ps_ucc101 printer as follows:
lpr -Pps_ucc101 graph.test
Mapping in SAS/GRAPH is available through PROC GMAP, which allows you to use already-prepared map files for most areas of the world. Map files for the United States and Canada contain detail down to the county (or equivalent) level. Map files are stored in a read-only directory.
To see the maps that are available, type
ls /usr/usc/sas/default/maps
Each map file has a descriptive name, followed by
.sas7bdat (which
indicates that it is a SAS data set generated with a 7.00 or
higher engine).
For example, one map of El Salvador is named
salvador.sas7bdat
The following example outlines the necessary SAS program statements for using a map file (the libref "maplib" is arbitrary):
libname maplib '/usr/usc/sas/default/maps';
proc gmap data=<your sas data set> map=maplib.salvador;