Chapter Contents

Previous

Next
SAS Companion for UNIX Environments

Using the PRINTTO Procedure

When you use the PRINTTO procedure with its LOG= and PRINT= options, you can route the SAS log or SAS procedure output to an external file or a fileref from any mode. Specify the external file or the fileref in the PROC PRINTTO statement. For example, the following example routes procedure output to /u/myid/output/prog1:

proc printto print='/u/myid/output/prog1' new;
run;
The NEW option causes any existing information in the file to be cleared. If you omit the NEW option from the PROC PRINTTO statement, the SAS log or procedure output is appended to the existing file.

If you plan to specify the same destination several times in your SAS program, you can assign a fileref to the file using a FILENAME statement. (See Assigning Filerefs with the FILENAME Statement for details and examples.) For example, you can use the PRINTER device type to send output directly to your system printer:

filename myoutput printer;
proc printto print=myoutput;
run;
Output will be sent to your default system printer or, if you have specified the SYSPRINT system option, to the printer specified with that option.

You can also use the PIPE device type to send output to a UNIX command. When you specify the print command, you may also want to specify a destination for (redirect) any error messages produced by the print command. Enclose the UNIX command in either single or double quotes. The following example associates the fileref MYOUTPUT with the print command lp, which will send output to the printer named myljet:

filename myoutput pipe 'lp -dmyljet';
proc printto print=myoutput;
run;
You can send the SAS log to the same printer by using the LOG= option:
filename mylog pipe 'lp -dmyljet';
proc printto log=mylog;
run;

The log and procedure output continue to be routed to the designated external file until another PROC PRINTTO statement reroutes them.

Any time you use PROC PRINTTO to route output, you must close the output device before PROC PRINTTO will release the output or log and send it to the destination you have specified. To close the output device, issue PROC PRINTTO without any parameters:

proc printto;
run;
Issuing PROC PRINTTO without any parameters closes the output device, generates output, and reroutes the log and procedure output to their default destinations. See Default Routings of the SAS Log and Output Files for a list of the default destinations.

For more information on PROC PRINTTO, see PRINTTO and SAS Procedures Guide.


Routing Output to an XPRINTER Device

You can use the XPRINTER device type to send output to the default printer device that has been selected in the Printer Setup dialog box. You can use the XPRINTER device in any mode, but if you use XPRINTER devices in batch mode, a display device must be available.

The following example uses the FILENAME statement to associate the fileref PRINTOUT with the default host printer device and routes the procedure output to that device:

filename printout xprinter;
proc printto log=printout print=printout;
run;
You cannot specify any options with the XPRINTER device type.

If you have not set up a printer device through the Printer Setup dialog box, the output will be printed, using a Courier font with no margins, to a generic Postscript file named prn.ps in your current working directory.

Note:   You can open only one XPRINTER device at a time during a SAS session. The OVP system option is not valid for XPRINTER devices; messages will be appended, not overwritten.  [cautionend]

As with other device types, you must close the XPRINTER device before output will be generated. To close the XPRINTER device and generate output, issue PROC PRINTTO without any parameters:

proc printto;
run;


Routing Output to a Terminal

In batch mode, you can direct output to a terminal by associating a fileref with a terminal and then using PROC PRINTTO to send output to that fileref. In the FILENAME statement, specify the TERMINAL device-type and the special file associated with the terminal. For example, the following statements send the SAS log to the terminal that is associated with the /dev/tty3 special file:

filename term terminal '/dev/tty3';
proc printto log=term;
run;


Simulating Forms in the Batch Environment

The FORMS subsystem is not available in batch mode. If you need to add printer control language (PCL, see Printer Control Language) to your print file, you can add the PCL through the DATA step.

The following example defines a print file, writes PCL and data to this print file, and sends the print file to the printer:

filename myoutput pipe 'lp -oraw -dmylaserjet';

/* set the print file to fileref */
proc printto print=myoutput;
run;

data one;
   x=1;
run;

/* write PCL to print file */
data _null_;
   file myoutput;
   put '1b'x '&l10';  /* landscape mode */
   put '1b'x '&2kS';  /* compressed mode */
run;

/* write data set to print file */
proc print data=one;
run;

/* release the print file */
proc printto;
run;
The '1b'x sequence is an escape sequence that is required before each PCL control sequence.


Chapter Contents

Previous

Next

Top of Page

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