SAS Output |
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. Interspersed with SAS statements are messages from SAS. 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.
NOTE: Copyright (c) 2007-2008 by SAS Institute Inc., Cary, NC, USA. 1 NOTE: SAS (r) 9.2 (TS1B0) 2 Licensed to SAS Institute Inc., Site 0000000001. 3 NOTE: This session is executing on the XP_PRO platform. 4 NOTE: SAS initialization used: real time 4.20 seconds cpu time 1.18 seconds 1 options pagesize=24 linesize=64 nodate; 5 2 3 data logsample; 6 4 infile '/u/abcdef/testdir/sampledata.dat'; 5 input LastName $ 1-12 ID $ Gender $ Birth : date7. 7 5 ! score1 score2 score3 6 score 6 ! 4 score5 score6; 7 format Birth mmddyy8.; 8 run; NOTE: The infile '/u/abcdef/testdir/sampledata.dat' is: 8 Filename=/u/abcdef/testdir/sampledata.dat, Owner Name=abcdef,Group Name=pubs, Access Permission=rw-r--r--, File Size (bytes)=296 NOTE: 5 records were read from the infile 9 '/u/abcdef/testdir/sampledata.dat'. The minimum record length was 58. The maximum record length was 59. NOTE: The data set WORK.LOGSAMPLE has 5 observations and 10 variables. 10 NOTE: DATA statement used: real time 0.08 seconds 11 cpu time 0.02 seconds 9 10 proc sort data=logsample; 12 11 by LastName; 12 NOTE: There were 5 observations read from the data set WORK.LOGSAMPLE. NOTE: The data set WORK.LOGSAMPLE has 5 observations and 10 variables. 13 NOTE: PROCEDURE SORT used: real time 0.03 seconds cpu time 0.01 seconds 13 proc print data=logsample; 14 14 by LastName; 15 run; NOTE: There were 5 observations read from the data set WORK.LOGSAMPLE. NOTE: PROCEDURE PRINT used: real time 0.09 seconds cpu time 0.05 seconds
The following list corresponds to the circled numbers in the SAS log shown above:
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 |
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 Language Reference: Dictionary and the LOG= system option in the documentation for your operating environment: OpenVMS, UNIX, Windows, or Z/OS.
For information about the SAS logging facility, see SAS Logging Facility in SAS Logging: Configuration and Programming Reference.
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:
appends the SAS log content to the existing SAS log
replaces the existing SAS log
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.
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.
Operating Environment Information: Under Windows, the buffered log contents are written periodically, using a SAS-specified interval.
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.
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 the LOGPARM=System Option in SAS Language Reference: Dictionary.
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.
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:
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.
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.
writes a user-specified message to the SAS log. Use the PUTLOG statement in a DATA step.
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.
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.
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 |
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:
specifies whether hardware information is written to the SAS log.
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.
specifies whether autoexec code in an input file is written to the log.
specifies the maximum number of observations for which data error messages are printed.
writes expanded statistics to the SAS log. The FULLSTATS system option is valid only under z/OS.
writes a subset of system performance statistics to the SAS log.
specifies whether ISPF error messages are written to the SAS log. The ISPNOTES system option is valid only under the z/OS operating environment.
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.
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.
writes macro execution trace information to the SAS log.
writes macro nesting execution trace information to the SAS log.
specifies whether SAS statements that are generated by macro execution are written to the SAS log.
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.
specifies whether news information that is maintained at your site is written to the SAS log.
specifies whether notes (messages beginning with NOTE) are written to the SAS log. NONOTES does not suppress error or warning messages.
specifies whether to write to the SAS log the values of all system options that are specified when SAS is invoked.
specifies whether error messages that are printed by SAS are overprinted.
specifies whether the SAS log and the listing file begin on a new page.
specifies whether extended lists of messages are written to the SAS log.
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.
specifies whether SAS writes source statements to the SAS log.
specifies whether SAS writes secondary source statements from files included by %INCLUDE statements to the SAS log.
specifies whether the results of resolving macro variable references are written to the SAS log.
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 Language Reference: Dictionary 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.
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.
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.
specifies whether to include additional information when files are listed in a SAS library.
specifies the maximum number of rows to display in the SAS log window.
specifies whether to update the date and time in the SAS log and in the listing file.
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.
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.
specifies the line size (printer line width) for the SAS log and SAS output that are used by the DATA step and procedures.
specifies whether to display notes, warning, and error messages in uppercase letters or lowercase letters.
specifies the character to be printed for missing numeric variable values.
controls whether the page number prints on the first title line of each page of printed output.
skips to a new page in the SAS log and continues printing from there.
specifies the number of lines that you can print per page of SAS output.
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 Language Reference: Dictionary.
The following system options pertain to the SAS log other than by the content and appearance of the SAS log:
specifies the destination for a copy of the SAS log.
specifies the destination for the SAS log when SAS is run in batch mode.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.