14_FunctionsAndOperatorsFMS
14_FunctionsAndOperatorsFMS
Introduction
Functions modify the value of one or more variables to produce a result (i.e.,
ROUND(2.33333) produces the value 2).
Operators are used to combine two items (i.e., the + operator combines Var1 and Var2 to
produce a sum, as in Var3=Var1+Var2).
Functions and operators appear within commands and are used for common tasks that
include extracting a year from a date, combining two numeric values, or testing logical
conditions.
Almost all functions require arguments enclosed in parentheses and separated by commas.
If arguments are required, do not place any spaces between the function name and the left
parenthesis. Syntax rules must be followed. Quotes that must enclose text strings are
displayed in question or prompt dialog boxes. Parentheses must enclose arithmetic
expressions and can explicitly control the order of operations. Parentheses also enclose
function arguments.
Syntax Notations
The following rules apply when reading this manual and using syntax:
Syntax Explanation
14-1
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Syntax Explanation
14-2
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Operators
There are various types of operators discussed in this appendix. The following types are
provided:
Operator Precedence
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:
14-3
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
& 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>
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
14-4
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
= 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>
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
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Newvar NUMERIC
ASSIGN Newvar =Age
LIST Newvar Age
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
14-5
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
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 Add
other is a string
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
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Newvar NUMERIC
ASSIGN Newvar = Age + 5
LIST Age Newvar
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]
14-6
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Comments
The expression is any valid logical expression in Epi Info.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Smoke
DEFINE Result TEXTINPUT
IF Age > 75 AND Sex = 2 THEN
ASSIGN Result="Senior"
END
SELECT Result = "Senior"
LIST Result Age Sex
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 (example 3 + 3).
• Subtraction – Basic arithmetic operator used for subtraction or negation; the result
of an arithmetic operator is usually a numeric value (example 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
14-7
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
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 (example
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:
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE var1 NUMERIC
ASSIGN var1=1250 MOD 100
DEFINE var2 NUMERIC
ASSIGN var2=1+1
DEFINE var3 NUMERIC
ASSIGN var3=2-1
DEFINE var4 NUMERIC
ASSIGN var4=1*1
DEFINE var5 NUMERIC
ASSIGN var5=8/4
DEFINE var6 NUMERIC
ASSIGN var6=5^2
LIST var1 var2 var3 var4 var5 var6
14-8
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
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.
14-9
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
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
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
SELECT Age>20
LIST Age Disease
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
SELECT Age<45
LIST Age Disease
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
SELECT Age>=38
LIST Age Disease
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
SELECT Age<>77
LIST Age Disease
LIKE Operator
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
14-10
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
The results appear in the Output window. Use LIST to view the selected records.
Examples
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE Sick NUMERIC
IF Disease LIKE "h*" THEN
ASSIGN Sick = 0
END
SELECT Disease LIKE "h*"
LIST Age Disease DateAdmitted Sick GRIDTABLE
NOT
Description
This operator reverses the True or False value of the logical expression that follows.
Syntax
NOT [Expression]
Comments
If the value of an expression is True, NOT returns the value False. If the expression is
False, NOT <expression> is True.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE NoVanilla YN
IF NOT Vanilla = (+) THEN
NoVanilla = (+)
ELSE
NoVanilla = (-)
END
FREQ NoVanilla Vanilla
VANILLA NOVANILLA
Yes No
No Yes
OR
14-11
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
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
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE IceCream YN
IF VANILLA=(+) OR CHOCOLATE=(+) THEN
IceCream=(+)
ELSE
IceCream=(-)
END
FREQ IceCream
No Yes Yes
Yes No Yes
No No No
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
14-12
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
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 And
expression1 expression2 Then result
is is is
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Oneicecream YN
IF Vanilla = (+) XOR Chocolate = (+) THEN
Oneicecream = (+)
ELSE
Oneicecream = (-)
END
LIST Vanilla Chocolate Oneicecream GRIDTABLE
14-13
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Functions
Do not put a space before the first parenthesis. Functions take the value of one or more
variables and return the result of a calculation or transformation.
ABS Function
Description
The ABS function returns the absolute value of a variable by removing the negative sign, if
any.
Syntax
ABS<variable>
Comments
Results will be numeric.
ABS
Value Function
-2 2
1 1
0 0
-0.0025 0.0025
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Age2 NUMERIC
DEFINE Age3 NUMERIC
ASSIGN Age2 = Age * -1
ASSIGN Age3 = ABS(Age2)
LIST Age Age2 Age3
14-14
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
DAY
Description
The DAY function extracts the day from the date.
Syntax
DAY (<variable>)
Comments
If the date is stored in a text variable, the function will not be processed, and will be null.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE CurrentDay NUMERIC
ASSIGN CurrentDay = DAY(01/15/2007)
LIST CurrentDay
DAYS
Description
The DAYS function returns the number of days between <var2> and <var1>. If any of the
variables or values included in the formula is not a date, the result will be null.
Syntax
DAYS(<var1>, <var2>)
Comments
If the date stored in <var1> is later (more recent) than the date in <var2>, the result is the
difference in days expressed as a negative number.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE SickDays NUMERIC
ASSIGN SickDays = DAYS(04/18/1940, DateOnset)
LIST SickDays GRIDTABLE
14-15
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
EXISTS
Description
This function returns True if a file exists. Otherwise, it returns False.
Syntax
EXISTS(<variable>)
<variable> represents the complete path and file name in text format.
Comments
If you do not have permission to access the file, a False may be returned.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE var1 TEXTINPUT
ASSIGN var1="C:\epi_info\epimap.exe"
IF EXISTS(Var1) =(+) then
DIALOG "Hello"
END
IF Exists("C:\Epi_Info\EpiInfo.mnu")=(+) then
DIALOG "File epiInfo.mnu exists"
END
EXP
Description
This function raises the base of the natural logarithm (e) to the power specified.
Syntax
EXP(<variable>)
Comments
This variable can be an existing numeric variable, a defined variable containing numbers,
or a numeric constant.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE ExpA NUMERIC
ASSIGN ExpA=EXP(Age)
LIST ExpA Age
14-16
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
FILEDATE
Description
This function returns the date a file was last modified or created. If FILEDATE is specified
with a file path that lacks a directory, the current directory is used. If FILEDATE is
specified without a file, or with a file that does not exist, the function returns missing.
Syntax
FILEDATE(<variable>)
The <variable> represents the complete file path and the name is text format.
Comments
This function is useful when several users are updating a large database.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:RHepatitis
DEFINE NewUpdate DATEFORMAT
ASSIGN NewUpdate=FILEDATE("C:\epi_info\Sample.mdb")
IF FILEDATE("C:\epi_info\Sample.mdb") > NewUpdate THEN
DIALOG "This information may be out of date. Please check the source."
TITLETEXT="Warning"
END
LIST NewUpdate
FINDTEXT
Description
This function returns the position in a variable in which the string is located.
Syntax
FINDTEXT(<variable1>,<variable2>)
Comments
If the sting is not found, the result is 0; otherwise it is a number corresponding to the
position of the string starting from the left. The first character is 1. If the result is 0, the
test was not found.
14-17
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE Var11 NUMERIC
VAR11=FINDTEXT("M",LASTNAME)
LIST LASTNAME Var11
FORMAT
Description
This function changes the format of one variable type to text in a specified format. If no
format is specified it returns text and converts a number to text.
Syntax
FORMAT(<variable>,["Format Specification"])
The <variable> represents a variable in any format and the [Format Specification] can
represent any of the following:
Date Formats
General Date 11/11/1999 05:34
Number Formats
General Number No thousand separator
Standard #,###.##
14-18
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Comments
Output may vary based on the specific configuration settings of the local computer.
Format(Time, "Long Time")
MyStr = Format(Date,"Long Date")
MyStr = Format(MyTime,"h:m:s")
Returns "17:4:23"
MyStr = Format(MyTime,"hh:mm:ssAMPM")
Returns "05:04:23 PM"
MyStr = Format(MyDate,"dddd, mmm yyyy")
Returns "Wednesday, ' Jan 27 1993". If format is not supplied, a string is returned.
MyStr = Format(23)
Returns "23".
User-defined formats
MyStr = Format(5459.4, "##,##0.00")
Returns "5,459.40"
MyStr = Format(334.9, "###0.00")
Returns "334.90"
MyStr = Format(5, "0.00%")
Returns "500.00%"
MyStr = Format("HELLO", "<")
Returns "hello"
MyStr = Format("This is it", ">")
Returns "THIS IS IT"
MyStr = Format("This is it", ">;*")
Returns "THIS IS IT"
Example
READ 'C:\Epi_Info\Refugee.MDB':Patient
14-19
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
HOUR
Description
This function returns a numeric value that corresponds to the hour recorded in a date/time
or time variable.
Syntax
HOUR(<variable>)
Comments
If the time is stored in a text variable, the function will not be processed, and the result will
be null.
14-20
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Local DATEFORMAT
ASSIGN Local = SYSTEMTIME
LIST Local
DEFINE hour1 NUMERIC
ASSIGN hour1=hour(local)
LIST Local hour1
HOURS
Description
This function returns the number of hours between <var1> and <var2> in numeric format.
Syntax
HOURS(<var1>, <var2>)
Comments
If the time stored in <var1> is later (more recent) than the time in <var2>, the result will
be the difference in hours expressed as a negative number. Both variables must contain
data in date, time, or date/time format. If any of the variables or values included in the
formula is not a date, the result will be null.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE hour1 NUMERIC
ASSIGN hour1=HOURS(Timesupper,Dateonset)
LIST hour1
LIST hour1 Timesupper Dateonset
LN
Description
The function LN returns the natural logarithm (logarithm in base e) of a numeric value or
variable. If the value is zero or null, it returns a null value.
14-21
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Syntax
LN(<variable>)
The <variable> can be an existing numeric variable, a defined variable containing numbers,
or a numeric constant.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Natlogofage NUMERIC
ASSIGN Natlogofage = LN(AGE)
LIST Age Natlogofage
LOG
Description
This function returns the base 10 logarithm (decimal logarithm) of a numeric value or
variable. If the value is 0 or null it returns a null value.
Syntax
LOG(<variable>)
The <variable> can be an existing numeric variable, a defined variable containing numbers,
or a numeric constant.
Comments
The results will be numeric.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Declog NUMERIC
ASSIGN Declog = LOG(Age)
LIST Age Declog
MINUTES
Description
This function returns the number of minutes between <var1> and <var2> in numeric
format.
14-22
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Syntax
MINUTES(<var1>, <var2>)
Comments
If the time stored in <var1> is later (more recent) than the time in <var2>, the result will
be the difference in minutes expressed as a negative number. Both variables must contain
data in date, time, or date/time format. If any of the variables or values included in the
formula is not a date, the result will be null.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Min1 NUMERIC
ASSIGN Min1=MINUTES(timesupper,dateonset)
LIST Min1
MONTH
Description
This function extracts the month from the date.
Syntax
MONTH(<variable>)
Comments
If the date is stored in a text variable, the function will not be processed, and the result will
be null.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE CurrMonth NUMERIC
ASSIGN CurrMonth = MONTH(01/01/2005)
LIST CurrMonth
14-23
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
MONTHS
Description
This function returns the number of months between <var1> and <var2>. If any of the
variables or values included in the formula is not a date, the result will be null.
Syntax
MONTHS(<var1>, <var2>)
Comments
If the date stored in <var1> is later (more recent) than the date in <var2>, the result will be
the difference in months expressed as a negative number.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE AgeMonths NUMERIC
ASSIGN AgeMonths = MONTHS(BirthDate,01/01/2000)
LIST AgeMonths
NUMTODATE
Description
This function transforms three numbers into a date format.
Syntax
NUMTODATE(<year>, <month>, <day>)
Comments
If the date resulting from the conversion is not valid (e.g., December 41, 2000), the date is
recalculated to the corresponding valid value (e.g., January 10, 2001). When <Year> ranges
between 0 and 29, it is represented as the respective year between 2000 and 2029. Values
from 30 to 99 are represented as the respective year between 1930 and 1999. The earliest
date that can be recorded is Jan 01, 100.
14-24
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Date
Day Month Year Created
02 02 1999 02/02/1999
60 01 1999 03/01/1999
15 18 2000 03/18/2001
99 99 99 06/07/0107
20 74 74 08/20/1974
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE day1 NUMERIC
DEFINE month1 NUMERIC
DEFINE year1 NUMERIC
ASSIGN day1= day(BirthDate)
ASSIGN month1 = month(BirthDate)
ASSIGN year1 = year(BirthDate)
define date2 DATEFORMAT
ASSIGN date2= NUMTODATE(year1,month1,day1)
LIST month1 day1 year1 date2 BirthDate GRIDTABLE
NUMTOTIME
Description
This function transforms three numbers into a time or date/time format.
Syntax
NUMTOTIME(<hour>, <minute>, <second>)
Comments
Time must be entered in 24-hour format. Invalid dates will be recalculated to the respective
valid time. If the number of the hour exceeds 24, the resulting variable will have a
date/time format and the default day 1 will be December 31, 1899.
14-25
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
00 00 00 12:00:00 AM
00 00 90 12:01:30 AM
15 84 126 04:26:06 PM
25 00 00 12/31/1899 1:00:00 AM
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE Var3 DATEFORMAT
ASSIGN Var3=SYSTEMTIME
DEFINE Hour1 NUMERIC
DEFINE Minute1 NUMERIC
DEFINE Second1 NUMERIC
ASSIGN Hour1=HOUR(VAR3)
ASSIGN Minute1=MINUTE(VAR3)
ASSIGN Second1=SECOND(VAR3)
DEFINE Time2 DATEFORMAT
ASSIGN Time2=NUMTOTIME(HOUR1,MINUTE1,SECOND1)
LIST Var3 Hour1 Minute1 Second1 Time2
RECORDCOUNT
Description
This function returns the number of records in the current View. In Analysis, this takes
into account any SELECT statement and value of the Process (Deleted) setting.
Syntax
RECORDCOUNT
14-26
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
IF RECORDCOUNT=0 THEN
DIALOG "No records found."
QUIT
END
RND
Description
This function generates a random number between <var1> and <var2>.
Syntax
RND(<min>, <max>)
• The <min> represents a number or numeric variable that corresponds to the
lowest value of the random number to be generated.
• The <max> represents a number or numeric variable that is one higher than the
highest possible value for the random number to be generated.
Comments
The random number generated is from <min> up to but not including <max>. For a set of
random numbers consisting of only 0 and 1, the syntax RND(0, 2) would be used to generate
a random number from 0 up to but not including 2. If the value for <min> is greater than
the value for <max> a syntax error results.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Random1 NUMERIC
DEFINE Random2 NUMERIC
DEFINE Random3 NUMERIC
ASSIGN Random1=RND(1,100)
ASSIGN Random2=RND(1,100)
ASSIGN Random3=RND(1,100)
LIST Random1 Random2 Random3
14-27
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
ROUND
Description
This function rounds the number stored in the variable to the closest integer. Positive
numbers are rounded up to the next higher integer if the fractional part is greater than or
equal to 0.5. Negative numbers are rounded down to the next lower integer if the fractional
part is greater than or equal to 0.5.
Syntax
ROUND(<variable>)
The <variable> can be an existing numeric variable, a defined variable containing numbers,
or a numeric constant.
Comments
The results are returned in numeric format.
Differences Between
TRUNC and ROUND
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
FREQ AGE
DEFINE Decade NUMERIC
ASSIGN Decade=ROUND(AGE/10)+1
LIST AGE Decade
SECONDS
Description
This function returns the number of seconds between <var1> and <var2> in numeric
format.
14-28
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Syntax
SECONDS(<var1>, <var2>)
Comments
If the time stored in <var1> is later (more recent) than the time in <var2>, the result will
be the difference in seconds expressed as a negative number. Both variables must contain
data in date, time or date/time format. If any of the variables or values included in the
formula is not a date, the result is null.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Sec1 NUMERIC
ASSIGN Sec1=SECONDS(Timesupper,DateOnset)
LIST Timesupper DateOnset Sec1
Syntax
SIN(<variable>)
The <variable> can be an existing numeric variable, a defined variable containing numbers,
or a numeric constant.
Comments
The variable is interpreted as the angle in radians. To convert degrees to radians, multiply
by pi (3.1415926535897932) divided by 180.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE SinA NUMERIC
DEFINE SinB NUMERIC
DEFINE CosA NUMERIC
DEFINE TanA NUMERIC
ASSIGN SinA=SIN(AGE)
ASSIGN SinB=SIN(AGE)*3.14/180
ASSIGN CosA=COS(AGE)
ASSIGN TanA=TAN(AGE)
LIST SinA CosA TanA SinB
14-29
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
SUBSTRING
Description
This function returns a string that is a specified part of the value in the string parameter.
Syntax
SUBSTRING(<variable>, [First], [Length])
Comments
This function cannot be used with non-string variables.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Text1 TEXTINPUT
ASSIGN Text1 ="James Smith"
DEFINE LName TEXTINPUT
ASSIGN LName = SUBSTRING(Text1,7,5)
LIST Text1 LName
SYSTEMDATE
Description
This function returns the date stored in the computer's clock.
Syntax
SYSTEMDATE
Comments
The SYSTEMDATE cannot be changed (assigned) from Classic Analysis. To use the
SYSTEMDATE for computations, a new variable must be defined.
14-30
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Example
To calculate next week's date:
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE TodayDate DATEFORMAT
ASSIGN TodayDate =SYSTEMDATE + 7
LIST TodayDate
SYSTEMTIME
Description
This function returns the time stored in the computer’s clock at the time the command is
executed.
Syntax
SYSTEMTIME
Comments
The SYSTEMTIME cannot be changed from Classic Analysis (assigned). To use the system
time for computations, a new variable must be defined.
Example
To calculate a time two hours after the current time:
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE Later DATEFORMAT
ASSIGN Later =SYSTEMTIME
LIST Later
ASSIGN Later =SYSTEMTIME+(120)
LIST Later
TRUNC
Description
This function removes decimals from a numeric variable, returning the integer part of the
number. This follows the same logic as rounding toward zero.
Syntax
TRUNC(<variable>)
The <variable> can be an existing numeric variable, a defined variable containing numbers,
or a numeric constant.
Comments
14-31
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:ADDFull
DEFINE Trc1 Numeric
ASSIGN Trc1 = TRUNC(ADDSC)
LIST Trc1 ADDSC
TXTTODATE
Description
This function returns a date value that corresponds to the string.
Syntax
TXTTODATE(<variable>)
Comments
The text variable can be in any format that can be recognized as a date (e.g., "Jan 1, 2000",
"1/1/2000").
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE Var1 TEXTINPUT
ASSIGN Var1="05/20/2006"
DEFINE Var2 DATEFORMAT
ASSIGN Var2=TXTTODATE(Var1)
DISPLAY DBVARIABLES
LIST Var1 Var2
TXTTONUM
Description
This function returns a numeric value that corresponds to the string.
Syntax
TXTTONUM(<variable>)
14-32
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Oswego
DEFINE Var1 TEXTINPUT
ASSIGN Var1="12345"
DEFINE Var2 NUMERIC
ASSIGN Var2=TXTTONUM(Var1)
LIST Var1 Var2
DISPLAY DBVARIABLES
UPPERCASE
Description
This function returns a string (text) variable that has been converted to uppercase.
Syntax
UPPERCASE(<variable>)
Comments
Only lowercase letters are converted to uppercase; all uppercase letters and non-letter
characters remain unchanged.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE LastName2 TEXTINPUT
ASSIGN LastName2 = UPPERCASE(LASTNAME)
LIST LastName2 LASTNAME
YEAR
Description
This function extracts the year from a date.
Syntax
YEAR(<variable>)
14-33
Epi Info™ 7 User Guide – Chapter 14 – Functions and Operators
Comments
The date argument is any expression that can represent a date. If the date variable
contains null, null is returned.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE CurrentYear NUMERIC
ASSIGN CurrentYear =YEAR(01/01/2006)
LIST CurrentYear
YEARS
Description
This function returns the number of years from <var1> to <var2> in numeric format. If any
of the variables or values included in the formula is not a date, the result will be null.
Syntax
YEARS(<var1>, <var2>)
Comments
If the date stored in <var1> is later (more recent) than the date in <var2>, the result will be
the difference in years expressed as a negative number.
Example
READ {C:\My_Project_Folder\Sample\Sample.prj}:Surveillance
DEFINE SurveyDate DATEFORMAT
ASSIGN SurveyDate=05/15/2001
DEFINE AgeYears NUMERIC
ASSIGN AgeYears =YEARS(BirthDate,SurveyDate)
MEANS AgeYears
LIST AgeYears BirthDate SurveyDate
14-34