Epi Info™ User Guide
Functions and Operators
Operators
There are various types of operators discussed in this appendix. The following types are provided:
- Arithmetic Operators are used to perform mathematical calculations.
- Assignment Operators are used to assign a value to a property or variable. Assignment Operators can be numeric, date, system, time, or text.
- Comparison Operators are used to perform comparisons.
- Concatenation Operators are used to combine strings.
- Logical Operators are used to perform logical operations and include AND, OR, or NOT.
- Boolean Operators include AND, OR, XOR, or NOT and can have one of two values, true or false.
Operator Precedence
If several operations occur in an expression, each part is evaluated and resolved in a predetermined order called Operator Precedence. Parentheses can be used to override the order of precedence and evaluate some parts of an expression before others. Operations within parentheses are always performed before those outside. Within parentheses, however, normal Operator Precedence is maintained.
If expressions contain operators from more than one category, arithmetic operators are evaluated first, comparison operators next, and logical operators last. Comparison operators all have equal precedence; they are evaluated in the left-to-right order in which they appear. Arithmetic and logical operators are evaluated in the following order of precedence:
Arithmetic |
Comparison |
Logical |
---|---|---|
Negation (-) |
Equality (=) |
Not |
Exponentiation (^) |
Inequality (<>) |
And |
Multiplication and division (*, /) |
Less than (<) |
Or |
Integer division (\) |
Greater than (>) |
Xor |
Modulus arithmetic (Mod) |
Less than or equal to (<=) |
|
Addition and Subtraction (+, -) |
Greater than or equal to (>=) |
|
String concatenation (&) |
Is |
|
If addition and subtraction, multiplication and division, occur together respectively in an expression, each operation is evaluated as it occurs from left to right.
The string concatenation operator (&) is not an arithmetic operator, but in precedence, it does fall after all arithmetic operators and before all comparison operators. The Is operator is an object reference comparison operator. It does not compare objects or their values; it checks only to determine whether two object references refer to the same object.
& Ampersand
Description
This operator forces text string concatenation of two expressions. Text concatenation operator connects or concatenates two values to produce a continuous text value.
Syntax
<expression> & <expression>
- The <expression> represents any valid logical expression.
Whenever an expression is not a string, it is converted to a String subtype. If both expressions are Null, the result is Null. However, if only one expression is Null, that expression is treated as a zero-length string ("") when concatenated with the other expression. Any expression that is Empty is also treated as a zero-length string.
Example
= Equal Sign
Description
This operator assigns a value to a variable or property. Comparison operator also used as an equal to; the result of comparison operators is usually a logical value, either true or false.
Syntax
<variable> <operator> <value>
- The <variable> represents any variable or any writable property.
- The <value> represents any numeric or string literal, constant, or expression.
Comments
The name on the left side of the equal sign can be a simple scalar variable or an element of an array. Properties on the left side of the equal sign can only be those writable properties at run time.
Example
Addition (+)
Description
This operator provides the sums of two numbers. Basic arithmetic operator used for addition; the result of an arithmetic operator is usually a numeric value.
Syntax
[expression1] <operator> [expression2]
Comments
Although the + operator can be used to concatenate two character strings, the & operator should be used for concatenation to eliminate ambiguity and provide self-documenting code. If + operator is used, there may be no way to determine whether addition or string concatenation will occur. The underlying subtype of the expressions determines the behavior of the + operator in the following way:
If |
Then |
---|---|
Both expressions are numeric |
Add |
Both expressions are strings |
Concatenate |
One expression is numeric and the other is a string |
Add |
If one or both expressions are Null expressions, the result is Null. If both expressions are Empty, the result is an integer subtype. However, if only one expression is Empty, the other expression is returned unchanged as a result.
Example
AND
Description
This operator performs logical conjunction on two Boolean expressions. If both expressions evaluate to True, the AND operator returns True. If either or both expressions evaluate to False, the AND operator returns False.
Syntax
[Logical Expression] AND [Logical Expression]
Comments
The expression is any valid logical expression in Epi Info.
Example
In this case, the value of "Senior" is assigned to all records that meet both criteria Age>75 and Sex=2.
ARITHMETIC
Description
These basic arithmetic operators can be used in combination with other commands. The result is a numeric value.
Syntax
[Expression] <Operator> [Expression]
- [Expression] is a numeric value or a variable containing data in numeric format.
Comments
The results are expressed in numeric format. The basic mathematical operators that can be used in Epi Info are as follows:
- Addition + Basic arithmetic operator used for addition; the result of an arithmetic operator is usually a numeric value (i.e., EX. 3 + 3).
- Subtraction - (Used for subtraction or negation.) Basic arithmetic operator used for subtraction or negation; the result of an arithmetic operator is usually a numeric value (i.e., EX. 3 – 1).
- Multiplication * (Asterisk) Basic arithmetic operator used for multiplication; the result of an arithmetic operator is usually a numeric value.
- Division / Basic arithmetic operator used for division; the result of an arithmetic operator is usually a numeric value.
- Exponentiation ^
- Modulus or Remainder MOD
Arithmetic operators are shown in descending order of precedence. Parentheses can be used to control the order in which operators are evaluated. The default order, however, frequently achieves the correct result.
While it is possible to do date math with dates considered as a number of days (e.g., IncubationDays = SymptomDateTime - ExposureDateTime), the behavior of the database services underlying Epi Info makes it more efficient to use time interval functions (e.g., IncubationDays = MINUTES(ExposureDateTime, Symptom DateTime)/[24*60]). For doing date math, the following rules apply:
Date + Date produces Date
Date - Date produces Days
Date * Date not permitted
Date / Date not permitted
Date ^ Date not permitted
Date + Number produces Date
Number + Date produces Number
The last two rules apply as well to other math operations: -, *, /, ^
The "zero day" for date math is December 30, 1899.
Example
Comparisons
Description
These comparison operators can be used in If, Then, and Select statements in Check Code and Analysis programs. Yes/No variables can only be tested for equality against other Yes/No constants (+), (-), and (.).
Operator |
Description |
---|---|
= |
Equal to Comparison operator used for equal to; the result of comparison operators is usually a logical value, either True or False. EX. A1 = B1. |
> |
Greater than comparison operator. Compares a value greater than another value; the result of comparison operators is usually a logical value, either True or False. Comparison operator used for comparing a value greater than another value; the result of comparison operators is usually a logical value, either True or False. EX. A1 > B1. |
< |
Less than comparison operator. Compares a value less than another value; the result of comparison operators is usually a logical value, either True or False. Comparison operator used for comparing a value less than another value; the result of comparison operators is usually a logical value, either True or False. EX. A1<B1. |
>= |
Greater than or equal to. |
<= |
Less than or equal to. |
<> |
Not equal to. |
LIKE |
Left side variable matches right side pattern; in pattern, ’*’ matches any number of characters, ’?’ matches any one character. |
Syntax
[Expression] <operator> [Expression]
[Expression] is any valid expression.
Comments
Comparison operators are executed from left to right. There is no hierarchy of comparison operators. The <> operator can be used only with numeric variables. For non-numeric variables, use NOT.
Example
LIKE
Description
This operator is used with the SELECT command to locate subsets of information using a wildcard search. LIKE can be used only to locate data in text variables and uses asterisks (*) to define the select value. It can also be used to create IF/THEN statements.
Syntax
SELECT <variable> LIKE "*value*"
SELECT <variable> LIKE "*val*"
SELECT <variable> LIKE "v*"
SELECT <variable> LIKE "*v"
- The select variable must be a text type. The value can be a whole or partial text value. Text variables must be enclosed in quotes.
Comments
The results appear in the Output window. Use LIST to view the selected records.
Examples
NOT
Description
This operator reverses the True or False value of the logical expression that follows.
Syntax
NOT [Expression]
The expression represents any valid logical expression in Epi Info.
Comments
If the value of an expression is True, NOT returns the value False. If the expression is False, NOT <expression> is True.
Example
VANILLA |
NOVANILLA |
---|---|
Yes |
No |
No |
Yes |
OR
Description
This operator returns True if one or the other or both expressions are True. If either expression evaluates to True, OR returns True. If neither expression evaluates to True, OR returns False.
Syntax
[Logical Expression] OR [Logical Expression]
[Logical Expression] represents any valid logical expression in Epi Info.
Example
VANILLA |
CHOCOLATE |
ICE CREAM |
---|---|---|
Yes |
Yes |
Yes |
No |
Yes |
Yes |
Yes |
No |
Yes |
No |
No |
No |
Yes |
Yes |
Yes |
XOR (eXclusive OR)
Description
This operator performs a logical exclusion on two expressions.
Syntax
[Logical Expression] XOR [Logical Expression]
The [Logical Expression] represents any valid logical expression in Epi Info 7 for Windows.
Comments
If one, and only one, of the expressions evaluates to True, the result is True. However, if either expression is Null, the result is also Null. When neither expression is Null, the result is determined according to the following table:
If expression1 is |
And expression2 is |
Then result is |
---|---|---|
True |
True |
False |
True |
False |
True |
False |
True |
True |
False |
False |
False |
Example
- Page last reviewed: August 18, 2016
- Page last updated: August 18, 2016
- Content source: