Most of the control flow statements in PROC OPTMODEL are familiar to users of the DATA step or the IML procedure. PROC OPTMODEL supports the IF statement, DO blocks, the iterative DO statement, the DO WHILE statement, and the DO UNTIL statement. You can also use the CONTINUE, LEAVE, and STOP statements to modify control flow.
PROC OPTMODEL adds the FOR statement.
This statement is similar in operation to an iterative DO loop. However, the iteration is performed over the members of an
index set. This form is convenient for iteration over all the locations in an array, since the valid array indices are also defined
using an index set. For example, the following statements initialize the array parameter A
, indexed by i
and j
, to random values sampled from a normal distribution with mean 0 and variance 1:
proc optmodel; set R=1..10; set C=1..5; number A{R, C}; for {i in R, j in C} A[i, j]=rannor(-1);
The FOR statement provides a convenient way to perform a statement such as the preceding assignment statement for each member of a set.