SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating Multiple Observations from a Single Record
Reading a Varying Number of Repeating Fields


Executing SAS Statements While a Condition Is True

Now consider how many times to read each record. Earlier, you created an index-variable named Quarter whose value ranged from 1 to 4  because there were four repeating fields.

     data perm.sales97;
        infile data97;
        input ID $4. @;
        do Quarter=1 to 4;
           input Sales : comma. @;
           output;
        end;
     run;
Now you want to read the record only while a value for Sales exists. Use a DO WHILE statement in place of the iterative DO statement.

     data perm.sales97;
        infile data97 missover;
        input ID $4. Sales : comma. @;
        DO WHILE statement

General form, DO WHILE loop:
DO WHILE (expression);
      . . . more SAS statements . . .
END;

where expression is any valid SAS expression and must be enclosed in parentheses.


The expression is evaluated at the top of the loop before any statements are executed. If the expression is true, the loop executes. If the expression is false the first time it is evaluated, then the loop never executes.

In the example below, the DO WHILE statement executes while the value of Sales is not equal to a missing value (which is represented by a period).

     data perm.sales97;
        infile data97 missover;
        input ID $4. Sales : comma. @;
        do while (sales ne .);


back||next


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

Terms of Use & Legal Information | Privacy Statement