Language Reference |
group statements as a unit
The DO statement specifies that the statements following the DO statement be executed as a group until a matching END statement appears. DO statements often appear in IF-THEN/ELSE statements, where they designate groups of statements to be performed when the IF condition is true or false.
For example, consider the following statements:
if x=y then do; i=i+l; print x; end; print y;The statements between the DO and END statements (called the DO group) are executed only if ; that is, they are executed only if all elements of are equal to the corresponding elements of . If any element of is not equal to the corresponding element of , the statements in the DO group are skipped and the next statement is executed. In this case, the next statement executed is as follows:
print y;DO groups can be nested; there is no limit imposed on the number of nested DO groups.
Here is an example of nested DO groups:
if y>z then do; if z=0 then do; z=b*c; x=2#y; end; end;It is good practice to indent the statements in a DO group as shown in the preceding example so that their positions indicate their levels of nesting.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.