Loops are fundamental to programming because they enable you to repeat a computation for various values of parameters. Different languages use different keywords to define the iteration statement. The most well-known statement is the "for loop," which is used by C/C++, MATLAB, R, and other languages. Older languages, such as FORTRAN and SAS, call the iteration statement a "do loop," but it is exactly the same concept. DO loops in the DATA step The basic iterative DO statement in SAS has the syntax DO value = start TO stop. An END statement marks the end of the loop, as shown in the following example: data A; do i = 1 to 5; y = i**2; /* values are 1, 4, 9, 16, 25 */ output; end; run; By default, each iteration of a DO statement increments the value of the counter by 1, but you can use the BY option to increment the counter by other amounts, including non-integer amounts. For example, each iteration of the following DATA step increments the value i by 0.5: data A; do i = 1 to 5 by 0.5; y = i**2; /* values are 1, 2.25, 4, ..., 16, 20.25, 25 */ output; end; run; You can also iterate "backwards" by using a negative value for the BY option: do i=5 to 1 by -0.5. Regards, Rachel Gomez
... View more