Directing Output to External Files with the PRINTTO Procedure

Using the PRINTTO procedure with its LOG= and PRINT= options, you can direct the SAS log or SAS procedure output to an external file in any mode. You can specify the name of the external file in the PROC PRINTTO statement. For example, the following statement directs procedure output to MYID.OUTPUT.DATA(MEMBER):
proc printto print='' new;
However, if you plan to specify the same external file several times in your SAS program, you can allocate the file with one of the following methods:
  • a FILENAME statement
  • a JCL DD statement
  • the TSO ALLOCATE command.
For details and examples, see Introduction to External Files. After the external file is allocated, use the PROC PRINTTO statement options LOG= or PRINT= at any point in your SAS session to direct the log or procedure output to the external file. Specify the fileref or the ddname that is associated with the external file. Here is an example that uses FILENAME statements to allocate external files for both the log and the procedure output:
filename printout 'myid.output.prtdata' disp=old;
filename logout 'myid.output.logdata' disp=old;
proc printto print=printout log=logout new;
The log and procedure output continue to be directed to the designated external file until another PROC PRINTTO statement redirects them.
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 existing sequential data sets. You must specify NEW when routing to a PDS or PDSE because you cannot append data to a member of a partitioned data set.
If you want to direct both the log and procedure output to partitioned data set members, the members must be in a PDSE or in different data sets. SAS enables you to write to two members of a PDSE, but not to two members of a PDS.
To return the log and procedure output to their default destinations, submit the following statements:
proc printto;
For a list of the default destinations, see Default Destinations for SAS Output Files.