The OPTMODEL Procedure

Expressions

Expressions are grouped into three categories based on the types of values they can produce: logical, set, and scalar (i.e., 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 of the following code (Output 6.6), 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;
 


The OPTMODEL Procedure

x y
0.5 1

Var x >= 0 <= 1                                                                 
 Var y <= 1                                                                      
 


Figure 6.6: Logical Expression in the VAR Statement

Contexts that expect a logical expression also accept numeric expressions. In such cases zero or missing values are interpreted as false, while 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. Index-set 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 "IF-THEN/ELSE Expression"). String lengths are assigned dynamically, so there is generally no padding or truncation of string values.

Table 6.3 shows the expression operators from lower to higher precedence (a higher precedence is given a larger number). Operators that have higher precedences 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 6.3: Expression Operator Table
Precedence Associativity Operator Alternates
logic expression operators
1left to rightOR | !
2unaryOR{index-set}
  AND{index-set}
3left to rightAND &
4unaryNOT ~ ^ \neg
5left to right< LT
  > GT
  <= LE
  >= GE
  = EQ
  ~= NE ^= \neg=
6left to rightIN
  NOT IN
7left to rightWITHIN
  NOT WITHIN
set expression operators
11 IF l THEN s1 ELSE s2 
12left to rightUNION  
  DIFF  
  SYMDIFF  
13unaryUNION{index-set} 
14left to rightINTER  
15unaryINTER{index-set} 
16left to rightCROSS  
17unarySETOF{index-set} 
 right to left.. TO
  .. e BY TO e BY
scalar expression operators
21 IF l THEN e  
  IF l THEN e1 ELSE e2 
22left to right|| !!
23left to right+ -  
24unarySUM{index-set} 
  PROD{index-set} 
  MIN{index-set} 
  MAX{index-set} 
25left to right* /  
26unary+ -  
 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 6.4: Primary Expression Table
Expression Description
identifier-expressionparameter/variable reference; see the section "Identifier Expressions"
name (arg-list)function call; arg-list is 0 or more expressions separated by commas
n numeric constant
. or .cmissing value constant
"string" or 'string' string constant
{ member-list }set constructor; member-list is 0 or more scalar expressions or tuple expressions separated by commas
{ index-set }index set expression; returns the set of all index set members
/ member(s) /set literal expression; compactly specifies a simple set value
( expression )expression enclosed in parentheses
< expr-list >tuple expression; used with set operations; contains one or more scalar expressions separated by commas
Previous Page | Next Page | Top of Page