Previous Page | Next Page

Printing and Routing Output

Using Commands to Print in UNIX Environments


Differences between the PRTFILE, PRINT, and FILE Commands

In the SAS windowing environment, you can use the PRTFILE, PRINT, and FILE commands to send the contents of the active window to an output device.

The following table lists the results of each of these commands.

Routing Output Commands
Command Action Performed
PRTFILE specifies the filename or fileref for your output.
FILE sends the contents of the active window to the filename or fileref you specify.
PRINT sends the contents of the active window either:
  • to your default printer when issued from the command line of the window.

  • to the location specified with the PRTFILE command.


Sending Output to a UNIX Command

If you want to send your output to a UNIX command, you can use the FILENAME statement. The FILENAME statement enables you to create filerefs that point to printers, plotters, or external files or filerefs that pipe to a UNIX command. For more information, see FILENAME Statement: UNIX.


Specifying the Print File

When you issue the PRINT command, SAS sends your output to your default printer unless you specify a print file. You can specify a print file in two ways:


Printing the Contents of a Window


Using PRTFILE and PRINT with a Fileref

You can use the PRTFILE command, followed by the PRINT command, to print the contents of windows. PRTFILE establishes the destination, and PRINT sends the contents of the window to that destination. If you do not specify a destination with the PRTFILE command, PRINT automatically sends the window contents to your default printer.


Steps for Sending Output Directly to a Printer

If you want to send output directly to a printer, you must first submit the FILENAME statement to assign a fileref to the PRINTER or PIPE device. For example, to print the contents of your Output window, complete the following steps:

Printing the Contents of Your Output Window
Step Action Example
1 Submit a FILENAME statement or FILENAME function to associate a fileref with a system printer (PRINTER device type) or a UNIX command (PIPE device type). Enclose the printer name or UNIX command in either single or double quotation marks.
filename myrpt printer 'bldga2';

or

filename ascout pipe 'lp -dmyljet';

For more information, see Examples of FILENAME Statements Using PRINTER and PIPE.

2 Issue the PRTFILE command as described in Specifying the Print File. Specify the fileref from your FILENAME statement or FILENAME function.
prtfile myrpt
3 Issue the PRINT command from the command line of the windows whose contents you want to print. If you are sending output to a system printer or if you are using forms-based printing, then you can print the contents of more than one window.
4 Enter A in the dialog box that appears to warn you that the destination file already exists. The A value tells SAS to append the window contents to the destination file.
5 Submit a FILENAME statement or FILENAME function to clear (deassign) the fileref.
filename myrpt clear;

To clear the print file setting, issue the PRTFILE CLEAR command.


Examples of FILENAME Statements Using PRINTER and PIPE

The following statement associates MyRpt with the system printer named BldgA2 and specifies two copies of every printout:

filename myrpt printer 'bldga2 -n2';

(See the documentation for your print command for information about other options that you can specify.)

The following statement enables you to print output using the lp command on the printer named myljet:

filename ascout pipe 'lp -dmyljet';

The following statement sends output to the lp command and redirects any error messages produced by this command to the LpError file in your home directory:

filename myrpt pipe 'lp 2>$HOME/lperror';

Note:   Redirecting standard error is allowed only in the Bourne and Korn shells.  [cautionend]

If you frequently use the same print command and destination, you can add the appropriate FILENAME statement to your autoexec file. See Customizing Your SAS Session by Using System Options for more information.


Using the FILE Command

You can use the FILE command to copy the contents of many different windows to external files. Issue the FILE command on the command line of the window whose contents you want to copy. For example, to copy the contents of the Log window to /u/myid/log/app1, issue the following command on the command line of the Log window:

file '/u/myid/log/app1'

If the file does not exist, SAS creates it. If the file already exists, a dialog box asks you whether you want to replace it or to append data to the existing data.

If you have already associated a fileref with your external file, you can use the fileref instead of the filename:

file myref

Note:   If you use the FILE command to save your output, carriage-control information is not saved (that is, page breaks are removed from the output). You might want to use the PRINT command with the FILE option instead:

PRINT FILE=fileref | 'pathname'
  [cautionend]

Previous Page | Next Page | Top of Page