DO DATA <variable = start TO stop>;
The DO DATA statement repeats a loop until an end-of-file condition occurs.
The arguments to the DO DATA statement are as follows:
is the name of a variable that indexes the loop.
is the starting value for the looping variable.
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, the program immediately jumps from the group and starts executing the statement that follows 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 not use GOTO statement and the LINK statement to jump out of a DO DATA group.
The following statements read data from an external file. The example reads the first 100 lines or until the end of file, whichever occurs first.
do data i = 1 to 100; input name $8.; end;
If you are reading data from a SAS data set, then you can use the following statements:
do data; /* read next obs until eof is reached */ read next var{x}; /* read only variable X */ end;
Be aware that the ALL keyword does not return an end-of-file condition. Consequently, the READ ALL statement is usually not used inside a DO DATA loop. If you use the READ ALL statement inside a DO DATA loop, you should use a looping variable or a statement that returns an end-of-file condition (such as READ NEXT) in order to avoid creating an infinite loop.