Expressions are grouped into three categories based on the types of values they can produce: logical, set, and scalar (that is, numeric or character).
Logical expressions test for a Boolean (true or false) condition. As in the DATA step, logical operators produce a value equal to either 0 or 1. A value of 0 represents a false condition, while a value of 1 represents a true condition.
Logical expression operators are not allowed in certain contexts due to syntactic considerations. For example, in the VAR
statement a logical operator might indicate the start of an option. Enclose a logical expression in parentheses to use it
in such contexts. The difference is illustrated by the output (Figure 5.6) of the following statements, where two variables, x
and y
, are declared with initial values. The PRINT statement and the EXPAND statement are used to check the initial values and the variable bounds, respectively.
proc optmodel; var x init 0.5 >= 0 <= 1; var y init (0.5 >= 0) <= 1; print x y; expand;
Figure 5.6: Logical Expression in the VAR Statement
x  y 

0.5  1 
Var x >= 0 <= 1 Var y <= 1 
Contexts that expect a logical expression also accept numeric expressions. In such cases zero or missing values are interpreted as false, and all nonzero nonmissing numeric values are interpreted as true.
Set expressions return a set value. PROC OPTMODEL supports a number of operators that create and manipulate sets. See the section OPTMODEL Expression Extensions for a description of the various set expressions. Indexset syntax is described in the section Index Sets.
Scalar expressions are similar to the expressions in the DATA step except for PROC OPTMODEL extensions. PROC OPTMODEL provides an IF expression (described in the section IFTHEN/ELSE Expression). String lengths are assigned dynamically, so there is generally no padding or truncation of string values.
Table 5.3 shows the expression operators from lower to higher precedence (a higher precedence is given a larger number). Operators
that have higher precedence are applied in compound expressions before operators that have lower precedence. The table also
gives the order of evaluation that is applied when multiple operators of the same precedence are used together. Operators
available in both PROC OPTMODEL and the DATA step have compatible precedences, except that in PROC OPTMODEL the NOT operator
has a lower precedence than the relational operators. This means that, for example, NOT 1 < 2
is equal to NOT (1 < 2)
(which is 0), rather than (NOT 1) < 2
(which is 1).
Table 5.3: Expression Operator Table
Precedence 
Associativity 
Operator 
Alternates 

Logic Expression Operators 

1 
Left to right 


2 
Unary 





3 
Left to right 


4 
Unary 


5 
Left to right 

















6 
Left to right 





7 
Left to right 





Set Expression Operators 

11 


12 
Left to right 






13 
Unary 


14 
Left to right 


15 
Unary 


16 
Left to right 


17 
Unary 


Right to left 






Scalar Expression Operators 

21 




22 
Left to right 


23 
Left to right 


24 
Unary 








25 
Left to right 


26 
Unary 


Right to left 






Primary expressions are the individual operands that are combined using the expression operators. Simple primary expressions can represent constants or named parameter and variable values. More complex primary expressions can be used to call functions or construct sets.
Table 5.4: Primary Expression Table
Expression 
Description 

identifierexpression 
Parameter/variable reference; see the section Identifier Expressions 
name 
Function call; arglist is 0 or more expressions separated by commas 
n 
Numeric constant 
. or .c 
Missing value constant 
“string” or 'string' 
String constant 
{ memberlist } 
Set constructor; memberlist is 0 or more scalar expressions or tuple expressions separated by commas 
{ indexset } 
Index set expression; returns the set of all index set members 
/ members / 
Set literal expression; compactly specifies a simple set value 
( expression ) 
Expression enclosed in parentheses 
< exprlist > 
Tuple expression; used with set operations; contains one or more scalar expressions separated by commas 