DO WHILE Statement


Executes statements repetitively while a condition is true

Valid: in a DATA step

Category: Control

Type: Executable

Syntax

DO WHILE ( expression );

  • ... more SAS statements ...

END ;

Arguments

( expression )

  • is any SAS expression, enclosed in parentheses. You must specify at least one expression .

Details

The expression is evaluated at the top of the loop before the statements in the DO loop are executed. If the expression is true, the DO loop iterates. If the expression is false the first time it is evaluated, the DO loop does not iterate even once.

Comparisons

There are three other forms of the DO statement:

  • The DO statement, the simplest form of DO-group processing, designates a group of statements to be executed as a unit, usually as a part of IF-THEN/ELSE statements.

  • The iterative DO statement executes statements between DO and END statements repetitively based on the value of an index variable.

  • The DO UNTIL statement executes statements in a DO loop repetitively until a condition is true, checking the condition after each iteration of the DO loop. The DO WHILE statement evaluates the condition at the top of the loop; the DO UNTIL statement evaluates the condition at the bottom of the loop.

    Note: If the expression is false, the statements in a DO WHILE loop do not execute. However, because the DO UNTIL expression is evaluated at the bottom of the loop, the statements in the DO UNTIL loop always execute at least once.

Examples

These statements repeat the loop while N is less than 5. The expression N<5 is evaluated at the top of the loop. There are five iterations in all (0, 1, 2, 3, 4).

 n=0;     do while(n<5);        put n=;        n+1;     end; 

See Also

Statements:

  • DO Statement on page 1143

  • DO Statement, Iterative on page 1144

  • DO UNTIL Statement on page 1148




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net