DO DATA Statements

The general form of the DO DATA statement is as follows:

DO DATA ;

The DATA keyword specifies that iteration stops when an end-of-file condition occurs. Other DO specifications exit after tests are performed at the top or bottom of a loop.

See Chapter 7: Working with SAS Data Sets, and Chapter 8: File Access, for more information about processing data.

You can use the DO DATA statement to read data from an external file or to process observations from a SAS data set. In the DATA step in Base SAS software, the iteration is usually implied. The DO DATA statement simulates this iteration until the end of a file is reached.

The following example reads data from an external file named MyData.txt that contains the following data:

Rick

2.40

3.30

Robert

3.90

4.00

Simon

3.85

4.25

The data values are read one at a time into the scalar variables Name, x, and y.

filename MyFile 'MyData.txt';
infile MyFile;                 /* infile statement       */
do data;                       /* begin read loop        */
   input Name $6. x y;         /* read a data value      */
   /* do something with each value */
end;
closefile MyFile;