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 |
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); 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
|
data perm.sales97; infile data97 missover; input ID $4. Sales : comma. @; do while (sales ne .); |
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.