LIST Statement

Writes to the SAS log the input data record for the observation that is being processed.

Valid in: DATA step
Categories: Action
CAS
Type: Executable

Syntax

LIST;

Without Arguments

The LIST statement causes the input data record for the observation being processed to be written to the SAS log.

Details

The LIST statement operates only on data that is read with an INPUT statement; it has no effect on data that is read with a SET, MERGE, MODIFY, or UPDATE statement.

In the SAS log, a ruler that indicates column positions appears before the first record listed.

For variable-length records (RECFM=V), SAS writes the record length at the end of the input line. SAS does not write the length for fixed-length records (RECFM=F), unless the amount of data read does not equal the record length (LRECL).

Comparisons

This table compares the LIST and PUT statements.

Action

LIST Statement

PUT Statement

Writes when

at the end of each iteration of the DATA step

immediately

Writes what

the input data records exactly as they appear

the variables or literals specified

Writes where

only to the SAS log

to the SAS log, the SAS output destination, or to any external file

Works with

INPUT statement only

any data-reading statement

Handles hexadecimal values

automatically prints a hexadecimal value if it encounters an unprintable character

represents characters in hexadecimal only when a hexadecimal format is given

Examples

Example 1: Listing Records That Contain Missing Data

This example uses the LIST statement to write to the SAS log any input records that contain missing data. Because of the #3 line pointer control in the INPUT statement, SAS reads three input records to create a single observation. Therefore, the LIST statement writes the three current input records to the SAS log each time a value for W2AMT is missing.

data employee;
   input ssn 1-9 #3 w2amt 1-6;
   if w2amt=. then list;
   datalines;
23456789
JAMES SMITH
356.79
345671234
Jeffrey Thomas
.
;

Log Listing of Missing Data

RULE:----+----1----+----2----+----3----+----4----+----5----+----
9   345671234
10  Jeffrey Thomas
11  .

The numbers 9, 10, and 11 are line numbers in the SAS log.

Example 2: Listing the Record Length of Variable-Length Records

This example uses as input an external file that contains variable-length ID numbers. The RECFM=V option is specified in the INFILE statement, and the LIST statement writes the records to the SAS log. When the file has variable-length records, as indicated by the RECFM=V option in this example, SAS writes the record length at the end of each record that is listed in the SAS log.

data employee;
   infile 'your-external-file' recfm=v;
   input id $;
   list;
run;

Log Listing of Variable-Length Records and Record Lengths

RULE:     ----+----1----+----2----+----3----+----4----+----5---
1         23456789 8
2         123456789 9
3         5555555555 10
4         345671234 9
5         2345678910 10
6         2345678 7

Example 3: Listing Hexadecimal Values for Input Data

Beginning with SAS 9.4M6, the /HEXLISTALL DATA statement option enables the LIST statement to write all lines of input data in hexadecimal format to the SAS log. In this example, a file that contains a valid line of data, a line of data that contains unprintable characters, and an invalid line of data are created. Next, a default DATA statement is used with the LIST statement to display the input data in hexadecimal format for the unprintable characters in the SAS log. Then the DATA statement is specified with the /HEXLISTALL argument and the LIST statement is used to display all of the input data in its hexadecimal format in the SAS log.

Here, the file f_out.txt is created. The file contains the three lines of data.

filename f_out 'f_out.txt' recfm=f lrecl=30; /* assign fileref */
data; 
   file f_out; 
   output; 
   put '123456789012345678901234567890';
   put '0102030405060708090A0B0C0D0E0F10111213141516171819202A2B2C2D'x;
   put 'Not a number                  ';
run;

The default settings in the DATA statement are used with the LIST statement to write the contents of the file to the SAS log. By default, hexadecimal format is displayed for the unprintable characters found on line two of the input file. Notes are displayed for the invalid data found on lines two and three.

data _null_;
infile  f_out length=len;  
input num; 
list;
run;

SAS Log of Hexadecimal Values for Unprintable Characters

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+---
1         123456789012345678901234567890
NOTE: Invalid data for num in line 2 1-25.


RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+---

2   CHAR  ......................... *+,-
    ZONE  000000000000000111111111122222
    NUMR  123456789ABCDEF01234567890ABCD
len=30 num=. _ERROR_=1 _N_=2
NOTE: Invalid data for num in line 3 1-3.
3         Not a number
len=30 num=. _ERROR_=1 _N_=3

The /HEXLISTALL argument is added to the DATA statement. The LIST statement now writes hexadecimal format for all lines of the input data in the SAS log. Notes are displayed for the invalid data found on lines two and three.

data _null_ /HEXLISTALL;
infile  f_out length=len;  
input num; 
list;
run;

filename f_out; /* deassign fileref */

SAS Log of Hexadecimal Values for All Input Data

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+---

1   CHAR  123456789012345678901234567890
    ZONE  333333333333333333333333333333
    NUMR  123456789012345678901234567890
NOTE: Invalid data for num in line 2 1-25.

2   CHAR  ......................... *+,-
    ZONE  000000000000000111111111122222
    NUMR  123456789ABCDEF01234567890ABCD
len=30 num=. _ERROR_=1 _N_=2
NOTE: Invalid data for num in line 3 1-3.

3   CHAR  Not a number
    ZONE  467262676667222222222222222222
    NUMR  EF4010E5D252000000000000000000
len=30 num=. _ERROR_=1 _N_=3

See Also

Last updated: June 17, 2025