Managing SAS Output under Windows |
Introduction to Routing Procedure Output and the SAS Log to a File |
This section provides examples of the most common methods of routing SAS procedure output and the SAS log to a file. Generally, this task is the same across operating environments and is discussed in the SAS Help and Documentation. However, the specification of external filenames and devices is system dependent. For complete information about the various ways to reference external files, see Referencing External Files.
You can route your SAS procedure output or the SAS log to a file in one of several ways. The method that you choose depends on the method you use to run SAS, the moment at which you make your decision to route the output or SAS log, and your personal preference.
Some methods of sending SAS procedure output or the SAS log to a file include using
the Save As dialog box, invoked either from the File menu, the pop-up menu for the window that you want to save, or by typing DLGSAVE in the command bar.
Using the Save As Dialog Box |
The easiest way to save the contents of the active window to a file is to select File Save As from the main SAS window, making sure that the active window (for example, Log or Output) contains the output that you want to save. For more information about the Save As dialog box, see Saving Files within the Enhanced Editor or Saving Files within the Program Editor.
Using the PRINTTO Procedure |
In batch SAS sessions, the SAS procedure output and the SAS log are written by default to files named filename.LST and filename.LOG, respectively, where filename is the name of your SAS job. For example, if your SYSIN file is MYPROG.SAS, the procedure output file is named MYPROG.LST, and the log file is named MYPROG.LOG. However, you can override these default filenames and send your output to any file that you choose. For example, suppose that your job contains the following statements, which assign the fileref MYOUTPUT to the file C:\SAS\FIRST.TXT. Then the PROC PRINTTO statement tells SAS to send any upcoming SAS procedure output to the file that is associated with MYOUTPUT.
filename myoutput 'c:\sas\first.txt'; proc printto print=myoutput; run; data uspres; input pres $ party $ number; datalines; Adams F 2 ; run; proc print; run;
Any PROC or DATA statements that follow these statements and that generate output send their output to the C:\SAS\FIRST.TXT file, not to the default procedure output file. If you want to return to the default file, issue an empty PROC PRINTTO statement like the following example:
proc printto; run; data uspres2; input pres $ party $ number; datalines; Lincoln R 16 Grant R 18 ; run; proc print; run;
Issuing these statements redirects the SAS procedure output to the default destination (filename.LST). In this way, you can send the output and log from different parts of the same SAS job to different files.
Note: If you route procedure output to a file, the resulting file can contain carriage-control characters. To suppress these control characters when you include the file in the Program Editor, set the RECFM= option to P in the FILENAME statement. Note that this action affects the way the file is read into the Program Editor, not the file itself.
If you want to send the SAS log to a specific file, use the LOG= option instead of the PRINT= option in the PROC PRINTTO statement. For more information about the PRINTTO procedure, see PRINTTO Procedure: Windows and Base SAS Procedures Guide.
Note: When you use the PRINTTO procedure to route SAS procedure output or the SAS log, the Status window does not reflect any rerouting of batch output but indicates that it is routing the procedure output file and log to filename.LST and filename.LOG.
Using SAS System Options |
You can use SAS system options to route your SAS output or SAS log to a file. For example, if you want to override the default behavior and send your procedure output from a batch SAS job to the file C:\SASOUTPUT\PROG1.TXT, you can invoke SAS with the following command:
SAS -SYSIN C:\SASPROGS\PROG1 -PRINT C:\SASOUTPUT\PROG1.TXT
This SAS command executes the SAS program PROG1.SAS and sends the procedure output to the file C:\SASOUTPUT\PROG1.TXT. You can treat the SAS log similarly by using the LOG system option instead of the PRINT system option. Two other related system options, the ALTPRINT and ALTLOG options, are explained in ALTPRINT System Option: Windows and ALTLOG System Option: Windows.
Note: The Status window does reflect the PRINT and LOG system options values when recording where the procedure output and log are being sent.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.