Macro Variable _OROPTMODEL_

The OPTMODEL procedure creates a macro variable named _OROPTMODEL_. You can inspect the execution of the most recently invoked solver from the value of the macro variable. The macro variable is defined at the start of the procedure and updated after each SOLVE statement is executed. The OPTMODEL procedure also updates the macro variable when an error is detected.

The _OROPTMODEL_ value is a string that consists of several KEYWORD=value items in sequence, separated by blanks; for example:

   STATUS=OK SOLUTION_STATUS=OPTIMAL OBJECTIVE=9 ITERATIONS=1 
   PRESOLVE_TIME=0 SOLUTION_TIME=0

The information contained in _OROPTMODEL_ varies according to which solver was last called. For lists of keywords and possible values, see the individual solver chapters.

If a value has not been computed, then the corresponding element is not included in the value of the macro variable. When PROC OPTMODEL starts, for example, the macro variable value is set to STATUS=OK because no SOLVE statement has been executed. If the STATUS= indicates an error, then the other values from the solver might not be available, depending on when the error occurred.

_STATUS_ and _SOLUTION_STATUS_ Parameters

In addition to generating the macro variable _OROPTMODEL_, the OPTMODEL procedure generates the predeclared string parameters _STATUS_ and _SOLUTION_STATUS_.

The value of _STATUS_ is equal to the STATUS= component of the _OROPTMODEL_ macro variable. The value of _STATUS_ is initially OK. The value is updated during the SOLVE statement and after statement execution errors.

The value of _SOLUTION_STATUS_ is equal to the SOLUTION_STATUS= component of the _OROPTMODEL_ macro variable. The value is initially an empty string. The value is updated during the SOLVE statement.

Macro and Statement Evaluation Order

PROC OPTMODEL reads a complete statement, such as a DO statement, before executing any code in it. But macro language statements are processed as the code is read. So you must be careful when using the _OROPTMODEL_ macro variable in code that involves SOLVE statements nested in loops or DO statements. The following statements demonstrate one example of this behavior:

   proc optmodel;
      var x, y;
      min z=x**2 + (x*y-1)**2;
      for {n in 1..3} do;
         fix x=n;
         solve;
         %put Line 1 &_OROPTMODEL_;
         put 'Line 2 ' (symget("_OROPTMODEL_"));
      end;
   quit;

In the preceding statements the %PUT statement is executed once, before any SOLVE statements are executed. It displays PROC OPTMODEL’s initial setting of the macro variable. But the PUT statement is executed after each SOLVE statement and indicates the expected solution status.