Handling SAS Output Under Linux

Bob Jackson
Department of Sociology
Duke University
Version 1.0
September 2007


Herein are described basic methods handling of Linux SAS output on departmental compute servers verstehen and paradigm.

There are three network printers to which Linux output may be directed via print spooling commands. Each printer is referenced by its mneumonic name:

1. Interactive Mode Output

SAS interactive output is written to the Log and Output windows. The former is a listing of the SAS code as executed along with notes, warnings and error messages. The latter is the output produced by SAS procedures.

Output from either window is printed by selecting the File > Print... menu option. The SAS:Print window opens. The first time used it will look as follows:

Click on the Use Forms button in the upper, left corner to alter window content to the following [subsequent SAS sessions will default to Forms printing]:

This window presents the system-wide printing defaults for SAS text output. The enscript spooling command converts ASCII files to nicely formatted PostScript output printed two pages per sheet in landscape orientation. The printer name designates the default printer, which is set to copy2. Change copy2 to lab to print on the Computer Lab printer.

It is best practice to save SAS Log and Output window content to files when a permanent record is needed. Save to files with File > Save As... menu sequences. Log window output will default to a .log filename extension and Output window contents to a .lst extension. Use file names that match those of the SAS program file. When working remotely, output files are easily downloaded to your local PC with a secure file transfer program.

2. Batch Mode Ouput

To the novice SAS user batch mode seems arcane, but the experienced SAS user comes to appreciate it for several reasons:

When run in batch mode, a SAS program will produce log and listing files. A log file (with file extension .log) is an authoritative listing of the SAS program as it is run accompanied by SAS notes, warnings and error messages. A listing file (with file extension .lst) is typically the output from any SAS procedure steps run by the job.

Batch mode SAS is run from the Linux command line, as demonstrated below. The command invokes SAS and instructs it to run the program sg101a.sas. By convention, SAS programs are given the extension .sas. The & (ampersand) instructs SAS to run in the background and return the user command prompt.

bobj:~/sas/sasgraph > sas sg101a.sas &
bobj:~/sas/sasgraph >

Execution of program sg101a.sas produces in the same directory the log file sg101a.log. If the program also generates procedural output, it is written to sg101a.lst. When debugging a SAS program, the listing file is often not produced until the program runs without errors. Batch programs can be modified and rerun. Each time it is run with the same filename, the log files are overwritten. So when doing a series of runs, make sure that each is done from a uniquely named SAS control statement file. Duplicate a SAS program with the copy (cp) statement and then modify it.

bobj:~/sas/sasgraph > cp sg101a.sas sg101b.sas

A SAS batch program is self-contained and independent of other SAS programs. This means that the SAS data sets used by the program must come from a permanent SAS library or be created by one or more DATA steps within the program. The WORK library exists only for the duration of the batch job.

Print batch output files from the command line with the enscript command. The command specifies the file to print, where to print it and what characteristics to apply to the output. Standard log and listing files are ASCII files. To conserve paper, print them in landscape orientation with 2 pages per sheet.

bobj:~/sas/sasgraph > enscript -2rG -Plab sg101a.log sg101a.lst

Breaking the above command options down:

The second example below uses the alternate printer destination and adds a device (D) key to force duplex (Duplex:true) printing.

bobj:~/sas/sasgraph > enscript -2rG -Pcopy2 -DDuplex:true sg101a.log

Use the man enscript command to display the online manual page for a full list of options. Use the space bar to page forward through the manual, the b key to page backward, and the q key to terminate the listing.

3. Graphical Output

Building SAS/GRAPH output can be a daunting task. The tutorial by Mike Zdeb and Robert Allison, SAS/GRAPH 101, nicely deconstructs the steps by systematically refining a basic plot to presentation-ready status. By tweaking an example from this paper, we illustrate how to produce SAS/GRAPH output for various purposes:

Fonts and Devices: Fonts in SAS/GRAPH are delivered as software fonts provided by SAS or as device specific hardware fonts. SAS supplies Bitstream software fonts from several font families, including Century, Hershey, Swiss and Zapf for all operating systems. Hardware fonts are associated with a particular graphics device supported by SAS. A graphics device can be a physical device such as a specific laser printer with standard built-in fonts or it can a be a particular type of output format (such as PDF), which allows a range of Adobe fonts.

We now proceed with a series of examples that incorporate slight variations to achieve different types of output. All are based on Example 14 from the Zdeb and Allison tutorial.

3.1. Example 1: Viewing Graph in a Display Manager Window

Below is the code used to generate the graph in an interactive SAS session and view it on screen in a Display Manager window. A typical approach would be to develop a graph like this in steps and viewing the results on the screen until you have a satisfactory product.

* Two line plot with a customized legend;
* Adapted from SAS/GRAPH 101 - Example 14;
* Filename:  sg101p0.sas;

options validvarname=upcase;
goptions reset=all ftext=swiss htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join h=2.5 l=1;
symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 "AMOUNT (IN BILLIONS)") minor=(n=3);
axis2 order=(1970 to 2000 by 5) minor=(n=4) offset=(2,2);

legend1 label=none value=(j=left "TOTAL" j=left "FEDERAL GOVT")
        mode=protect position=(top inside left)
        cborder=blue cshadow=blue
        across=1 shape=line(10);

title h=4 f=swissb "National Health Care Expenditures: 1970-2000";
footnote j=right "Source: Health-United States-2003";

proc  gplot  data=t112;
  plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend=legend1;
  format nh_tot comma.;
  run; quit;

Note the following:

3.2. Example 2: Output a Portable Network Graphic

Minor modification to the first example will produce a PNG file.

* Two line plot with a customized legend output to a PNG file;
* Adapted from SAS/GRAPH 101 - Example 14;
* Filename:  sg101p1.sas;

filename  gout1  '~bobj/sas/sasgraph/ex14.png';

options validvarname=upcase;
goptions reset=all device=png gsfname=gout1 xpixels=760 ypixels=570
         ftext=swiss htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join h=2.5 l=1;
symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 "AMOUNT (IN BILLIONS)") minor=(n=3);
axis2 order=(1970 to 2000 by 5) minor=(n=4) offset=(2,2);

legend1 label=none value=(j=left "TOTAL" j=left "FEDERAL GOVT")
        mode=protect position=(top inside left)
        cborder=blue cshadow=blue
        across=1 shape=line(10);

title h=4 f=swiss "National Health Care Expenditures: 1970-2000";
footnote j=right "Source: Health-United States-2003";

proc  gplot  data=t112;
  plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend=legend1;
  format nh_tot comma.;
  run; quit;

Note the following:

The resulting graph is incorporated into this document below:


ex14.png


3.3. Example 3: Output a PDF

Due to the better quality of results, we illustrate a bit more complicated approach to producing a PDF document involving use of the PDF Universal Printer controlled through the SAS Output Delivery System. [These tools can be used to write a series of tables and graphs to one PDF document. See SAS Technical Support Document TS-659 Exporting SAS/GRAPH Output to PDF Files

* Two line plot with a customized legend output to a PDF file;
* Adapted from SAS/GRAPH 101 - Example 14;
* Filename:  sg101p2.sas;

options orientation=landscape validvarname=upcase;
goptions reset=all device=sasprtc ftext='Helvetica'
         htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join h=2.5 l=1;
symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 "AMOUNT (IN BILLIONS)") minor=(n=3);
axis2 order=(1970 to 2000 by 5) minor=(n=4) offset=(2,2);

legend1 label=none value=(j=left "TOTAL" j=left "FEDERAL GOVT")
        mode=protect position=(top inside left)
        cborder=blue cshadow=blue
        across=1 shape=line(10);

title h=4 f='Helvetica/bo' "National Health Care Expenditures: 1970-2000";
footnote j=right "Source: Health-United States-2003";

ods listing close;
ods pdf file='~bobj/sas/sasgraph/ex14.pdf' notoc;

proc  gplot  data=t112;
  plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend=legend1;
  format nh_tot comma.;
  run; quit;

ods pdf close;
ods listing;

Note the following:

You may open a PDF graph on verstehen with acroread (the Linux version of Adobe Acrobat) and print it to a standard or color printer. When using the File>Print menu sequence to print a color graph, make sure that the printer command is specified as /usr/bin/lp -d color.

bobj: ~/sas/sasgraph > acroread ex14.pdf &

A PDF graph can be included in a personal web page and accessed with the Acrobat plugin of your browser.

3.4. Example 4: Output a PostScript File

A PostScript image provides the best method for inserting a graph into a word processing document, as illustrated with this final example.

* Two line plot with a customized legend output to a PostScript file;
* Adapted from SAS/GRAPH 101 - Example 14;
* Filename:  sg101p3.sas;

filename  gout3  '~bobj/sas/sasgraph/ex14.ps';

options validvarname=upcase;
goptions reset=all device=ps gsfname=gout3 ftext='Helvetica'
         htext=2 gunit=pct ctext=green csymbol=blue;

symbol1 v=dot i=join h=2.5 l=1;
symbol2 v=dot i=join h=2.5 l=3;

axis1 label=(angle=90 "AMOUNT (IN BILLIONS)") minor=(n=3);
axis2 order=(1970 to 2000 by 5) minor=(n=4) offset=(2,2);

legend1 label=none value=(j=left "TOTAL" j=left "FEDERAL GOVT")
        mode=protect position=(top inside left)
        cborder=blue cshadow=blue
        across=1 shape=line(10);

title h=4 f='Helvetica-Bold' "National Health Care Expenditures: 1970-2000";
footnote j=right "Source: Health-United States-2003";

proc  gplot  data=t112;
  plot (nh_tot fg_tot)*year/overlay vaxis=axis1 haxis=axis2 caxis=blue legend=legend1;
  format nh_tot comma.;
  run; quit;

Note the following:

To incorporate a PostScript image into a Word 2003 document:

  1. Open a Word document.
  2. Select Insert > Picture > From File....

  3. Navigate to the file location.
  4. Set Files of type to All Files (*.*).

  5. Double-click the desired file.
  6. In the Convert File dialog box, select Encapsulated PostScript and click OK.

  7. The document is loaded. It may be resized and repositioned.

4. References


Computing Home | Sociology Home | Arts & Sciences Home | Duke Home