There are several ways to save a log file in SAS. However, the most straightforward way is to use the PROC PRINTTO Procedure.
PROC PRINTTO procedure redirects log output and procedure output to files or printers. To save the output in an external file, specify the external file or the fileref in the PROC PRINTTO statement.
Specify the path and file name in the LOG= option of the procedure. Then, specify a PROC PRINTTO step without options to direct it back to the editor again.
PROC PRINTTO <options>;
Options in Proc Printto
LABEL= It provides a description for a SAS log or procedure output stored in a SAS catalog entry.
LOG= The name of the external file where you want to save the log.
NEW It replaces the file instead of appending it to it. If you do not specify the New option, the Log will be appended to the existing file whenever the code runs.
PRINT= It is used for printing file specifications to procedure output to a permanent external file or SAS catalog entry or printer.
UNIT=nn routes the output to the file identified by the fileref.
A simple example of a Proc Printto Procedure
proc printto log="/home/9to5sas/saslogs/log1.txt" new; run; data class; set sashelp.cars; where origin="Asia"; run; proc printto; run;
When routing the SAS log, include a RUN statement in the PROC PRINTTO. If the RUN statement is omitted, the following DATA or PROC step’s first line is not directed to the new file. (This is because a statement is not executed until it reaches a step boundary.)
The NEW option causes any existing information in the file to be cleared. For example, suppose you omit the NEW option from the PROC PRINTTO statement. In that case, the SAS log or procedure output is appended to the existing sequential data sets.
Suppose you plan to specify the same destination several times in your SAS program. In that case, you can assign a fileref to the file using a FILENAME statement.
For example, you can use the PRINTER device type to send the output directly to your system printer:
For a list of the default destinations, see Default Destinations for SAS Output Files.
filename myoutput printer; proc printto print=myoutput; run;
After PROC PRINTTO executes, all procedure output is sent to the alternate location until you execute another PROC PRINTTO statement or until your program or session ends.
proc printto; run;
How to save Output to External Files with the PRINTTO Procedure
You can use the PRINTTO procedure with PRINT= options to save the SAS procedure output to an external file in any mode.
Here is an example that uses FILENAME statements to assign external files for the procedure output:
filename printout '/home/subhroster20070/9to5sas/output.txt'; /* Redirect output to print.txt and log.txt */ /* new: force creation of new file rather than appending to existing one */ proc printto print=printout new; proc print data=sashelp.class; run; /* Restore redirection */ proc printto; run;