Chapter Contents |
Previous |
Next |
%DO, Iterative |
Type: | Macro statement |
Restriction: | Allowed in macro definitions only |
See also: | %END |
Syntax | |
Example | |
Generating a Series of DATA Steps |
Syntax |
%DO
macro-variable=start %TO stop <%BY increment>;
text and macro language statements |
%END; |
You can change the value of the index variable during processing. For example, using conditional processing to set the value of the index variable beyond the stop value when a certain condition is met ends processing of the loop.
The first time the %DO group iterates, macro-variable is equal to start. As processing continues, the value of macro-variable changes by the value of increment until the value of macro-variable is outside the range of integers included by start and stop.
Example |
This example illustrates using an iterative %DO group in a macro definition.
%macro create(howmany); %do i=1 %to &howmany; data month&i; infile in&i; input product cost date; run; %end; %mend create; %create(3)
When you execute the macro CREATE, it generates these statements:
DATA MONTH1; INFILE IN1; INPUT PRODUCT COST DATE; RUN; DATA MONTH2; INFILE IN2; INPUT PRODUCT COST DATE; RUN; DATA MONTH3; INFILE IN3; INPUT PRODUCT COST DATE; RUN;
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.