Language Reference

DO DATA Statement

repeats a loop until an end of file occurs

DO DATA <variable=start TO stop>;

The inputs to the DO DATA statement are as follows:
variable
is the name of a variable indexing the loop.

start
is the starting value for the looping variable.

stop
is the stopping value for the looping variable.

The DO DATA statement is used for repetitive DO loops that need to be exited upon the occurrence of an end of file for an INPUT, READ, or other I/O statement. This form is common for loops that read data from either a sequential file or a SAS data set.

When an end of file is reached inside the DO DATA group, IML immediately jumps from the group and starts executing the statement following the END statement. DO DATA groups can be nested, where each end of file causes a jump from the most local DO DATA group. The DO DATA loop simulates the end-of-file behavior of the SAS DATA step. You should avoid using GOTO and LINK statements to jump out of a DO DATA group.

Examples of valid statements follow. The first example inputs the variable NAME from an external file for the first 100 lines or until the end of file, whichever occurs first. Here is the code:

  
    do data i=1 to 100; 
       input name $8.; 
    end;
 
Or, if reading from a SAS data set, then you can use the following code:
  
    do data;             /* read next obs until eof is reached */ 
       read next var{x}; /* read only variable X               */ 
    end;
 

Previous Page | Next Page | Top of Page