|
Chapter Contents |
Previous |
Next |
| Programming Statements |
The DO statement also serves the feature of iteration. With a DO statement, you can repeatedly execute a set of statements until some condition stops the execution. A DO statement is iterative if you specify it with any of the following iteration clauses. The type of clause determines when to stop the repetition.
| Clause | DO Statement | |
| DATA | DO DATA statement | |
| variable = start TO stop < BY increment > | iterative DO statement | |
| WHILE(expression) | DO WHILE statement | |
| UNTIL(expression) | DO UNTIL statement |
A DO statement can have any combination of these four iteration clauses, but a given DO statement must be specified in the order listed in the preceding table.
infile 'mydata'; /* infile statement */
do data; /* begin read loop */
input xx; /* read a data value */
x=x//xx; /* concatenate values */
end; /* end loop */
do i=10 to 100 by 10;
do while(count<5);
print count;
count=count+1;
end;
print COUNT four times.
The UNTIL clause is like the WHILE clause except that the expression is evaluated at the bottom of the loop. This means that the loop always executes at least once.
For example, if the variable COUNT has an initial value of 1, the statements
do until(count>5);
print count;
count=count+1;
end;
print COUNT five times.
|
Chapter Contents |
Previous |
Next |
Top |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.