Function Expressions

Most functions that can be invoked from the DATA step or the %SYSFUNC macro can be used in PROC OPTMODEL expressions. Certain functions are specific to the DATA step and cannot be used in PROC OPTMODEL. Functions specific to the DATA step include these:

  • functions in the LAG, DIF, and DIM families

  • functions that access the DATA step program data vector

  • functions that access symbol attributes

The CALL statement can invoke SAS library subroutines. These subroutines can read and update the values of the parameters and variables that are used as arguments. See the section CALL Statement for an example.

OPTMODEL arrays can be passed to SAS library functions and subroutines using the argument syntax:

OF array-name[*] $\ms {[}$ . suffix $\ms {]}$ ;

The array-name is the name of an array symbol. The optional suffix allows auxiliary values to be referenced, as described in section Suffixes.

The OF argument form is resolved into a sequence of arguments, one for each index in the array. The array elements appear in order of the array’s index set. The OF array form is a compact alternative to listing the array elements explicitly.

As an example, the following statements use the CALL SORTN function to sort the elements of a numeric array:

proc optmodel;
   number original{i in 1..8} = sin(i);
   number sorted{i in 1..8} init original[i];
   call sortn(of sorted[*]);
   print original sorted;

The output is shown in Figure 5.7. Eight arguments are passed to the SORTN routine. The original column shows the original order, and the sorted column has the sorted order.

Figure 5.7: Sorting Using an OF Array Argument

[1] original sorted
1 0.84147 -0.95892
2 0.90930 -0.75680
3 0.14112 -0.27942
4 -0.75680 0.14112
5 -0.95892 0.65699
6 -0.27942 0.84147
7 0.65699 0.90930
8 0.98936 0.98936


Note: OF array arguments cannot be used with function calls in declarations when any of the function arguments depend on variables, objectives, or implicit variables.