Chapter Contents

Previous

Next
SAS Companion for UNIX Environments

Using 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 PRINT command sends the contents of the active window to either your default printer or to the location you specify with the PRTFILE command. With the PRTFILE, you can specify either a filename or a fileref. The FILE command sends the contents of the active window to the filename or fileref that you specify. With the FILENAME statement, you can create filerefs that point to printers, plotters, or external files or filerefs that pipe your output to a UNIX command. You can use the PRINT and PRTFILE commands with forms or with host printing.


Using the PRINT Command with Forms

Use the PRINT command to route the contents of a window to your default printer. This is the easiest method of printing output. For example, issue the PRINT command from the command line of your OUTPUT window to send the contents of that window to your default printer.

To route the contents of a window to a printer that is not your default printer, you can use select a different form through the pull-down menu:

File
[arrow]
Print Utilities
[arrow]
Set Form Name...
If you do not have host printing turned on (see Printing from the SAS System), all subsequent print operations will use the form that you specify.

Note:   Multiple forms can be specified for the same printer. Select a form that uses a printer other than your default printer.  [cautionend]

You can also select a different form by specifying the FORM= option with the PRINT command. For example, to copy output to a printer destination that is described in a form named MYOUTPUT, you enter the following command-line command:

print form=myoutput

For more information on forms, see Defining Forms.


Using PRTFILE and PRINT with a Fileref

You can also use the PRTFILE command, followed by the PRINT command, to print the contents of windows. This method enables you to override some of the defaults that are established by the FORM subsystem, such as the destination.

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.

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

  1. Submit a FILENAME statement or FILENAME function to associate a fileref with a system printer (PRINTER device type), a host printer device (XPRINTER device type), or a UNIX command (PIPE device type). Enclose the printer name or UNIX command in either single or double quotes.

    For example, 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 allows 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]

    The following statement associates MYRPT with your default host printer device:

    filename myrpt xprinter;
    MYRPT can be defined as an external file or as a Postscript (or PCL) printer. You cannot specify options with the XPRINTER device, and you can open only one XPRINTER device at a time during a SAS session.

    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 for more information.

  2. Issue the PRTFILE command as described in Specifying the Print File. Specify the fileref from your FILENAME statement or FILENAME function. For example:
    prtfile myrpt

  3. From the command line of the windows whose contents you want to print, issue the PRINT command. 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. If you want to print the contents of any other windows, issue the PRINT command from the command line of those windows. A requestor window warns you that the destination file already exists. Enter A in the requestor window to append the window contents to the destination file.

    Note:   If you are using host printing to send output to a file, the file will always be replaced; APPEND is not valid for an XPRINTER device.  [cautionend]

  4. From the command line of the first window that you printed, issue the FREE command to close the print file or device. You must close the output device before output is generated. If you do not close the print file or output device before you end your SAS session, SAS will close it for you when you exit your session.

  5. Submit a FILENAME statement or FILENAME function to clear (deassign) the fileref. Your output is not actually printed until you perform this step. For example:
    filename myrpt clear;

To return to forms-based printing, issue the PRTFILE CLEAR command.


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 requestor window 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 may want to use the PRINT command with the FILE option instead:

PRINT FILE=fileref | 'pathname'
  [cautionend]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.