- March 25, 2021 at 10:30 pm #49300
1.basic iterative DO statement in SAS has the syntax DO value = start TO stop
do i = 1 to 4;
answer + 3;
do j = 2 to 12 by 2;
do i = 20 to 1 by -1;
DO i = 1, 2, 3, 4, 5;
DO j = ‘a’, ‘b’, ‘c’, ‘d’;
DO i = 1 to 6;
DO j = 1 to 9;
PROC PRINT data = abc;
TITLE ‘it is done!’;
DO statement with a WHILE clause to iterate while a condition is true. the expression, in this case is evaluated at the top of the loop.
The condition is checked before each iteration, which implies that you should intialize the stopping condition prior to the loop.
DO UNTIL loop, SAS executes the DO loop until the expression you’ve specified is true. Here’s the general form of a DO UNTIL loop:
DO UNTIL (expression);
where expression is any valid SAS expression enclosed in parentheses. The key thing to remember is that the expression is not evaluated until the bottom of the loop.
Therefore, a DO UNTIL loop always executes at least once. As soon as the expression is determined to be true, the DO loop does not execute again.March 25, 2021 at 10:57 pm #49302
4.Do over loops with array
array nvars _numeric_;
do over nvars;
if nvars > 3 then nvars = .;
courtesy- ListendataMarch 26, 2021 at 12:56 am #49304
do i = 1 to 5 by 0.5 while(y < 20); y = i**2; /* values are 1, 2.25, 4, ..., 16, 20.5 */ output; end;
- You must be logged in to reply to this topic.