Generating Data with DO Loops |
Constructing DO
Loops |
Decrementing DO Loops
You can decrement a DO loop by specifying a negative value for the BY clause. For example, the specification in this iterative DO statement decreases the index variable by 1, resulting in values of 5, 4, 3, 2, 1. V DO index-variable=5 to 1 by -1; more SAS statements END; When you use a negative BY clause value, the start value must always be greater than the stop value in order to decrease the index variable during each iteration. start stop V V DO index-variable=5 to 1 by -1; more SAS statements END;
You can also specify how many times a DO loop executes by listing items in a series. DO index-variable=2,5,9,13,27; more SAS statements END; When the DO loop executes, it executes once for each item in the series. The index variable equals the value of the current item. You must separate each item in the series with a comma. To list items in a series, you must specify either
DO index-variable=2,5,9,13,27; more SAS statements END;
DO index-variable='MON','TUE','WED','THR','FRI'; more SAS statements END;
DO index-variable=win,place,show; more SAS statements END; Variable names must represent either all numeric or all character values. Do not enclose variable names in quotation marks. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.