The SAS Log

Structure of the Log

The SAS log is a record of everything that you do in your SAS session or with your SAS program. Original program statements are identified by line numbers. SAS messages are interspersed with SAS statements. These messages might begin with the words NOTE, INFO, WARNING, ERROR, or an error number, and they might refer to a SAS statement by its line number in the log.
For example, in the following output, the number 1 prints to the left of the OPTIONS statement. This means that it is the first line in the program. In interactive mode, SAS continues with the sequence of line numbering until you end your session. If you submit the program again (or submit other programs in your current SAS session), the first program line number will be the next consecutive number.
Operating Environment Information: The SAS log appears differently depending on your operating environment. See the SAS documentation for your operating environment.
Sample SAS Log
NOTE: Copyright (c) 2002-2010 by SAS Institute Inc., Cary, NC, USA.  1
NOTE: SAS (r) Proprietary Software 9.2 (TS2B0)  2
      Licensed to SAS Institute Inc., Site 000000001.  3
NOTE: This session is executing on the XP_PRO  platform.  4



NOTE: SAS initialization used:
      real time           2.18 seconds
      cpu time            0.70 seconds

1    options pagesize=24 
2    linesize=64 pageno=1 nodate;  5
3    data logsample;  6
5       infile
5  ! '\\myserver\my-directory-path\sampledata.dat';  7
6       input LastName $ ID $ Gender $ Birth : date7. score1
6  ! score2 score3 score4 score5 score6 score7 score8;
7       format Birth mmddyy8.;
8    run;

NOTE: The infile
      '\\myserver\my-directory-path\sampledata.dat' is:  8

      Filename=\\myserver\my-directory-path\sampledata.dat,
      RECFM=V,LRECL=256,File Size (bytes)=296,
      Last Modified=08Jun2009:15:42:26,
      Create Time=08Jun2009:15:42:26

NOTE: 5 records were read from the infile  9
      '\\myserver\my-directory-path\sampledata.dat'.
      The minimum record length was 58.
      The maximum record length was 59.
NOTE: The data set WORK.LOGSAMPLE has 5 observations and 12
      variables.  10
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds  11
      cpu time            0.01 seconds


9
10   proc sort data=logsample;  12
11      by LastName;
12   run;

NOTE: There were 5 observations read from the data set
      WORK.LOGSAMPLE.
NOTE: The data set WORK.LOGSAMPLE has 5 observations and 12
      variables.  13
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


13
14   proc print data=logsample;  14
15      by LastName;
16   run;

NOTE: There were 5 observations read from the data set
      WORK.LOGSAMPLE.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
The following list corresponds to the circled numbers in the SAS log shown above:
1 copyright information
2 SAS system release used to run this program
3 name and site number of the computer installation where the program ran
4 platform used to run the program
5 OPTIONS statement to set a page size of 24, a line size of 64, and to suppress the date in the output
6 SAS statements that make up the program (if the SAS system option SOURCE is enabled)
7 long statement continued to the next line. Note that the continuation line is preceded by an exclamation point (!), and that the line number does not change.
8 input file information-notes or warning messages about the raw data and where they were obtained (if the SAS system option NOTES is enabled)
9 the number and record length of records read from the input file (if the SAS system option NOTES is enabled)
10 SAS data set that your program created; notes that contain the number of observations and variables for each data set created (if the SAS system option NOTES is enabled)
11 reported performance statistics when the STIMER option or the FULLSTIMER option is set
12 procedure that sorts your data set
13 note about the sorted SAS data set
14 procedure that prints your data set

The SAS Log in Interactive Mode

In interactive mode, the SAS log is opened when SAS starts. The SAS log is not named until you save it in the active window. The name that you specify must follow the file naming conventions for your operating environment. The SAS log cannot be saved automatically in interactive mode. However, SAS can create a second copy of the SAS log if the ALTLOG= system option is set either at SAS invocation or in a configuration file.

The SAS Log in Batch, Line, or Objectserver Modes

Overview of the SAS Log in Batch, Line, or Objectserver Modes

In batch, line, and objectserver modes, you can configure the SAS log by using the LOG= system option and the LOGPARM= system option if the LOGCONFIGLOC= system option is not specified when SAS starts. If the LOGCONFIGLOC= system option is specified, logging is performed by the SAS logging facility. The LOGPARM= option is ignored. The LOG= option is honored only when the %S{App.Log} conversion character is specified in the logging configuration file.
The following sections discuss the log options that you can configure using the LOGPARM= system option and how you would name the SAS log for those options when the logging facility has not been initiated.
The LOG= system option names the SAS log. The LOGPARM= system option enables you to perform the following tasks:
  • append or replace an existing SAS log
  • determine when to write to the SAS log
  • start a new SAS log under certain conditions
For information about these log system options, see the LOGPARM= System Option in SAS System Options: Reference and the LOG= system option in the documentation for your operating environment:

Appending to or Replacing the SAS Log

If you specify a destination for the SAS log in the LOG= system option, SAS verifies if a SAS log already exists. If the log does exist, you can specify how content is written to the SAS log by using the OPEN= option of the LOGPARM= system option:
OPEN=APPEND
appends the SAS log content to the existing SAS log
OPEN=REPLACE
replaces the existing SAS log
OPEN=REPLACEOLD
replace the existing SAS log if it is older than 24 hours
In the following SAS command, both the LOG= and LOGPARM= system options are specified in order to replace an existing SAS log that is more than one day old:
sas -sysin "my-batch-program"  -log "c:\sas\SASlogs\mylog" 
    -logparm open=replaceold
The OPEN= option is ignored when the ROLLOVER= option of the LOGPARM= system option is set to a specific size, n.

Specifying When to Write to the SAS Log

Content can be written to the SAS log either as the log content is produced or it can be buffered and written when the buffer is full. By default, SAS writes to the log when the log buffer is full. By buffering the log content, SAS performs more efficiently by writing to the log file periodically instead of writing one line at a time.
Windows Specifics: Under Windows, the buffered log contents are written periodically, using an interval specified by SAS.
You use the WRITE= option of the LOGPARM= system option to configure when the SAS log contents are written. Set LOGPARM=“WRITE=IMMEDIATE” for the log content to be written as it is produced and set LOGPARM=“WRITE=BUFFERED” for the log content to be written when the buffer is full.

Rolling Over the SAS Log

Overview of Rolling Over the SAS Log: The SAS log can get very large for long running servers and for batch jobs. By using the LOGPARM= and LOG= system options together, you can specify to roll over the SAS log to a new SAS log. When SAS rolls over the log, it closes the log and opens a new log.
The LOGPARM= system option controls when log files are opened and closed and the LOG= system option names the SAS log file. Logs can be rolled over automatically, when a SAS session starts, when the log has reached a specific size, or not at all. By using formatting directives in the SAS log name, each SAS log can be named with unique identifiers.
Using Directives to Name the SAS Log: For the SAS log, a directive is a processing instruction that is used to uniquely name the SAS log. By using directives, you can add information to the SAS log name such as the day, the hour, the system node name, or a unique identifier. You can include one or more directives in the name of the SAS log when you specify the log name in the LOG= system option. For example, if you want the SAS log name to include the year, the month, and the day, the LOG= system option might look like this:
-log='c:\saslog\#Y#b#dsas.log'
When the SAS log is created on February 2, 2009, the name of the log is 2009Feb02sas.log.
Directives resolve only when the value of the ROLLOVER= option of the LOGPARM= system option is set to AUTO or SESSION. If directives are specified in the log name and the value of the ROLLOVER option is NONE or a specific size, n, the directive characters, such as #b or #Y, become part of the log name. Using the example above for the LOG= system option, if the LOGPARM= system option specifies ROLLOVER=NONE, the name of the SAS log is #Y%b#dsas.log.
For a complete list of directives, see LOGPARM= System Option in SAS System Options: Reference.
Automatically Rolling Over the SAS Log When Directives Change: When the SAS log name contains one or more directives and the ROLLOVER= option of the LOGPARM= system option is set to AUTO, SAS closes the log and opens a new log when the directive values change. The new SAS log name contains the new directive values.
The follow table shows some of the log names that are created when SAS is started on the second of the month at 6:15 AM, using this SAS command:
sas -objectserver -log "london#n#d#%H.log"
-logparm
"rollover=auto"
The directive #n inserts the system node name into the log name. #d adds the day of the month to the log name. #H adds the hour to the log name. The node name for this example is Thames. The log for this SAS session rolls over when the hour changes and when the day changes.
Log Names for Rolled Over Logs
Rollover Time
Log Name
SAS initialization
londonThames0206.log
First rollover
londonThames0207.log
Last log of the day
londonThames0223.log
First log past midnight
londonThames0300.log
Rolling Over the SAS Log by SAS Session: To roll over the log at the start of a SAS session, specify the LOGPARM=“ROLLOVER=SESSION” option when SAS starts. SAS resolves the system-specific directives by using the system information obtained when SAS starts. No roll over occurs during the SAS session and the log file is closed at the end of the SAS session.
Rolling Over the SAS Log by the Log Size: To roll over the log when the log reaches a specific size, specify the LOGPARM=“ROLLOVER=n” option when SAS starts. n is the maximum size of the log, in bytes, and it cannot be smaller than 10K (10,240) bytes. When the log reaches the specified size, SAS closes the log and appends the text “old” to the filename. For example, londonold.log. SAS opens a new log using the value of the LOG= option for the log name, ignoring the OPEN= option of the LOGPARM= system option so that it never writes over an existing log file. Directives in log names are ignored for logs that roll over based on log size.
To ensure unique log filenames between servers, SAS creates a lock file that is based on the log filename. The lock filename is logname.lck, where logname is the value of the LOG= option. If a lock file exists for a server log and another server specifies the same log name, the log and lock filenames for the second server have a number appended to the names. The numbers begin with 2 and increment by 1 for subsequent requests for the same log filename. For example, if a lock exists for the log file london.log, the second server log would be london2.log and the lock file would be london2.lck.
No SAS Log Roll Over: To not roll over the log at all, specify the LOGPARM= “ROLLOVER=NONE” option when SAS starts. Directives are not resolved and no rollover occurs. For example, if LOG=“March#b.log”, the directive #b does not resolve and the log name is March#b.log.

Writing to the Log in All Modes

In all modes, you can instruct SAS to write additional information to the log by using the following statements:
PUT statement
writes selected lines (including text strings and DATA step variable values) to the SAS log in the current iteration of a DATA step. If a FILE statement with the LOG destination executes before a PUT statement, the PUT statement output is directed to a destination that is specified by the FILE statement.
%PUT statement
enables you to write a text string or macro variable values to the SAS log. %PUT is a SAS macro program statement that is independent of the DATA step and can be used anywhere.
PUTLOG statement
writes a user-specified message to the SAS log. Use the PUTLOG statement in a DATA step.
LIST statement
writes to the SAS log the input data records for the data line that is being processed. The LIST statement operates only on data that are read with an INPUT statement. It has no effect on data that are read with a SET, MERGE, MODIFY, or UPDATE statement. Use the LIST statement in a DATA step.
DATA statement with /NESTING option
writes to the SAS log a note for the beginning and end for each nesting level of DO-END and SELECT-END statements. This enables you to debug mismatched DO-END and SELECT-END statements.
ERROR statement
sets the automatic _ERROR_ variable to 1 and (OPTIONAL) writes to the log a message that you specify. Use the ERROR statement in a DATA step.
Use the PUT, PUTLOG, LIST, DATA, and ERROR statements in combination with conditional processing to debug DATA steps by writing selected information to the log.

Customizing the Log

Altering the Contents of the Log

When you have large SAS production programs or an application that you run on a regular basis without changes, you might want to suppress part of the log. SAS system options enable you to suppress SAS statements and system messages, as well as to limit the number of error messages. Note that all SAS system options remain in effect for the duration of your session or until you change the options. You should not suppress log messages until you have successfully executed the program without errors.
The following list describes some of the SAS system options that you can use to alter the contents of the log:
CPUID | NOCPUID
specifies whether hardware information is written to the SAS log.
ECHO
specifies a message to be written to the SAS log while SAS initializes. The ECHO system option is valid only under the Windows and UNIX operating environments.
ECHOAUTO | NOECHOAUTO
specifies whether autoexec code in an input file is written to the log.
ERRORS=n
specifies the maximum number of observations for which data error messages are printed.
FULLSTATS
writes expanded statistics to the SAS log. The FULLSTATS system option is valid only under z/OS.
FULLSTIMER
writes a subset of system performance statistics to the SAS log.
ISPNOTES
specifies whether ISPF error messages are written to the SAS log. The ISPNOTES system option is valid only under the z/OS operating environment.
LOGPARM “OPEN=APPEND | REPLACE | REPLACEOLD”
when a log file already exists and SAS is opening the log, the LOGPARM option specifies whether to append to the existing log or to replace the existing log. The REPLACEOLD option specifies to replace logs that are more than one day old.
MEMRPT
specifies whether memory usage statistics are written to the SAS log for each step. The MEMRPT system option is valid only under the z/OS operating environment.
MLOGIC
writes macro execution trace information to the SAS log.
MLOGICNEST
writes macro nesting execution trace information to the SAS log.
MPRINT | NOMPRINT
specifies whether SAS statements that are generated by macro execution are written to the SAS log.
MSGLEVEL=N | I
specifies the level of detail in messages that are written to the SAS log. If the MSGLEVEL system option is set to N, the log displays notes, warnings, and error messages only. If MSGLEVEL is set to I, the log displays additional notes pertaining to index usage, merge processing, and sort utilities, along with standard notes, warnings, and error messages.
NEWS=external-file
specifies whether news information that is maintained at your site is written to the SAS log.
NOTES | NONOTES
specifies whether notes (messages beginning with NOTE) are written to the SAS log. NONOTES does not suppress error or warning messages.
OPLIST
specifies whether to write to the SAS log the values of all system options that are specified when SAS is invoked.
OVP | NOOVP
specifies whether error messages that are printed by SAS are overprinted.
PAGEBREAKINITIAL
specifies whether the SAS log and the listing file begin on a new page.
PRINTMSGLIST | NOPRINTMSGLIST
specifies whether extended lists of messages are written to the SAS log.
RTRACE
produces a list of resources that are read during SAS execution and writes them to the SAS log if a location is not specified for the RTRACELOC= system option. The RTRACE system option is valid only for the Windows and UNIX operating environments.
SOURCE | NOSOURCE
specifies whether SAS writes source statements to the SAS log.
SOURCE2 | NOSOURCE2
specifies whether SAS writes secondary source statements from files included by %INCLUDE statements to the SAS log.
SYMBOLGEN | NOSYMBOLGEN
specifies whether the results of resolving macro variable references are written to the SAS log.
VERBOSE
specifies whether SAS writes to the batch log or to the computer monitor the values of the system options that are specified in the configuration file.
See SAS System Options: Reference for more information about how to use these and other SAS system options.
Operating Environment Information: See the documentation for your operating environment for other options that affect log output.

Customizing the Appearance of the Log

The following SAS statements and SAS system options enable you to customize the log. Customizing the log is helpful when you use the log for report writing or for creating a permanent record.
DATE system option
controls whether the date and time that the SAS job began are printed at the top of each page of the SAS log and any output created by SAS.
DETAILS | NODETAILS
specifies whether to include additional information when files are listed in a SAS library.
DMSLOGSIZE= system option
specifies the maximum number of rows to display in the SAS log window.
DTRESET | NODTRESET
specifies whether to update the date and time in the SAS log and in the listing file.
FILE statement
enables you to write the results of PUT statements to an external file. You can use the following two options in the FILE statement to customize the log for that report.
LINESIZE=value specifies the maximum number of columns per line for reports and the maximum record length for data files.
PAGESIZE=value specifies the maximum number of lines to print on each page of output.
Note: FILE statement options apply only to the output specified in the FILE statement, whereas the LINESIZE= and PAGESIZE= SAS system options apply to all subsequent listings.
LINESIZE= system option
specifies the line size (printer line width) for the SAS log and SAS output that are used by the DATA step and procedures.
MSGCASE
specifies whether to display notes, warning, and error messages in uppercase letters or lowercase letters.
MISSING= system option
specifies the character to be printed for missing numeric variable values.
NUMBER system option
controls whether the page number prints on the first title line of each page of printed output.
PAGE statement
skips to a new page in the SAS log and continues printing from there.
PAGESIZE= system option
specifies the number of lines that you can print per page of SAS output.
SKIP statement
skips a specified number of lines in the SAS log.
STIMEFMT= system option
specifies the format to use for displaying the read and CPU processing times when the STIMER system option is set. The STIMEFMT= system option is valid under Windows, VMS, and UNIX operating environments.
Operating Environment Information: The range of values for the FILE statement and for SAS system options depends on your operating environment. See the SAS documentation for your operating environment for more information.
For more information about how to use these and other SAS system options and statements, see SAS System Options: Reference.

Other System Options That Affect the SAS Log

The following system options pertain to the SAS log other than by the content and appearance of the SAS log:
ALTLOG= system option
specifies the destination for a copy of the SAS log.
LOG= system option
specifies the destination for the SAS log when SAS is run in batch mode.
LOGAPPLNAME
specifies a SAS session name that can be used for SAS logging.