Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Language Reference

DO Statement, Iterative

iteratively executes a DO group

DO variable=start TO stop <BY increment>;

The inputs to the DO 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.

increment
is an increment value.
When the DO group has this form, the statements between the DO and END statements are executed repetitively. The number of times the statements are executed depends on the evaluation of the expressions given in the DO statement.

The start, stop, and increment values should be scalars or expressions with evaluations that yield scalars. The variable is given a new value for each repetition of the group. The index variable starts with the start value, then is incremented by the increment value each time. The iterations continue as long as the index variable is less than or equal to the stop value. If a negative increment is used, then the rules reverse so that the index variable decrements to a lower bound. Note that the start, stop, and increment expressions are evaluated only once before the looping starts.

For example, the statements

   do i=1 to 5 by 2;
      print 'THE VALUE OF I IS:' i;
   end;
produce the output
                                                   I
                        THE VALUE OF I IS:         1


                                                   I
                        THE VALUE OF I IS:         3


                                                   I
                        THE VALUE OF I IS:         5

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.