Previous Page | Next Page

Analyzing Your SAS Session with the SAS Log

Writing to the SAS Log


Default Output to the SAS Log

The previous sample logs show the information that appears on the log by default. You can also write to the log by using the PUT statement or the LIST statement within a DATA step. These statements can be used to debug your SAS programs.


Using the PUT Statement

The PUT statement enables you to write information that you specify, including text strings and variable values, to the log. Values can be written in column, list, formatted, or named output style.(footnote 1) Used as a screening device, the PUT statement can also be a useful debugging tool. For example, the following statement writes the values of all variables, including the automatic variables _ERROR_ and _N_, that are defined in the current DATA step:

put _all_;

The following program reads the data set OUT.SAT_SCORES and uses the PUT statement to write to the SAS log the records for which the score is 500 points or more.

The following partial output shows that the records are written to the log immediately after the SAS statements:

libname out 'your-data-library';

data _null_;
   set out.sat_scores;
   if SATscore >= 500 then put test gender year;
run;

Writing to the SAS Log with the PUT Statement

NOTE: Libref OUT was successfully assigned as follows: 
      Engine:        V8 
      Physical Name: YOUR-DATA-LIBRARY
123  
124  data _null_;
125     set out.sat_scores;
126     if SATscore >= 500 then put test gender year;
127  run;
Math m 1972
Math m 1973
Math m 1974
   .
   .
   .
  

Using the LIST Statement

Use the LIST statement in the DATA step to list on the log the current input record. The following program shows that the LIST statement, like the PUT statement, can be very effective when combined with conditional processing to write selected information to the log:

data out.sat_scores3;
   infile 'your-input-file';
   input test $ gender $ year SATscore @@;
   if SATscore < 500 then delete;
   else list;
run;

When the LIST statement is executed, SAS causes the current input buffer to be printed following the DATA step. The following partial output shows the results. Note the presence of the columns ruler before the first line. The ruler indicates that input data has been written to the log. It can be used to reference column positions in the input buffer. Also notice that, because two observations are created from each input record, the entire input record is printed whenever either value of the SATscore variable from that input line is at least 500. Finally, note that the LIST statement causes the record length to be printed at the end of each line (in this case, each record has a length of 36). This feature of the LIST statement works only in operating environments that support variable-length (as opposed to fixed-length) input records.

Writing to the SAS Log with the LIST Statement

NOTE: Libref OUT was successfully assigned as follows: 
      Engine:        V8 
      Physical Name: YOUR-DATA-LIBRARY
248  data out.sat_scores3;
249     infile 'YOUR-DATA-FILE';
250     input test $ gender $ year SATscore @@;
251     if SATscore < 500 then delete;
252     else list;
253  run;
NOTE: The infile 
      'YOUR-DATA-FILE' is:
      
      File 
      Name=YOUR-DATA-FILE,
      Owner Name=userid,Group Name=dev,
      Access Permission=rw-r--r--,
      File Size (bytes)=1998

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7
1         Verbal m 1972 531  Verbal f 1972 529 36
2         Verbal m 1973 523  Verbal f 1973 521 36
3         Verbal m 1974 524  Verbal f 1974 520 36
   .
   .
   .
53        Math   m 1997 530  Math   f 1997 494 36
54        Math   m 1998 531  Math   f 1998 496 36
NOTE: 54 records were read from the infile 
      'YOUR-DATA-FILE'.
      The minimum record length was 36.
      The maximum record length was 36.
NOTE: SAS went to a new line when INPUT statement reached past the end of a 
      line.
NOTE: The data set OUT.SAT_SCORES3 has 69 observations and 4 variables.

FOOTNOTE 1:   Named output enables you to write a variable's name as well as its value to the SAS log. For more information, see "PUT, Named" in the Statements section of SAS Language Reference: Dictionary. [arrow]

Previous Page | Next Page | Top of Page