The OPTMODEL Procedure |
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;
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 TablePrecedence | Associativity | Operator | Alternates |
logic expression operators | |||
1 | left to right | OR | | ! |
2 | unary | OR{index-set} | |
AND{index-set} | |||
3 | left to right | AND | & |
4 | unary | NOT | ~ ^ |
5 | left to right | < | LT |
> | GT | ||
<= | LE | ||
>= | GE | ||
= | EQ | ||
~= | NE ^= = | ||
6 | left to right | IN | |
NOT IN | |||
7 | left to right | WITHIN | |
NOT WITHIN | |||
set expression operators | |||
11 | IF l THEN s1 ELSE s2 | ||
12 | left to right | UNION | |
DIFF | |||
SYMDIFF | |||
13 | unary | UNION{index-set} | |
14 | left to right | INTER | |
15 | unary | INTER{index-set} | |
16 | left to right | CROSS | |
17 | unary | SETOF{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 | |||
22 | left to right | || | !! |
23 | left to right | + - | |
24 | unary | SUM{index-set} | |
PROD{index-set} | |||
MIN{index-set} | |||
MAX{index-set} | |||
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 6.4: Primary Expression TableExpression | Description |
identifier-expression | parameter/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 .c | missing 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 |
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.