Epi Info™ User Guide

Command Reference


Analysis Commands: ASSIGN

Description
This command assigns numeric or string expression results to a variable. It may be a database variable in a form or data table, or a user-defined variable created by the DEFINE command in a program.

Syntax

ASSIGN <variable> = <expression>

LET <variable> = <expression>

(ASSIGN and LET may be omitted)

<variable> = <expression>

  • The <variable> represents a variable in a database or a defined variable created in a program.
  • The <expression> represents any valid arithmetic or string expression.

Program Specific Feature
If the right side of the assignment does not contain a field variable (one in a database table), or a variable that depends on a field variable, the assignment is made immediately.

DEFINE TestYear NUMERIC
ASSIGN TestYear = 2000

The following code contains two view variables, OnsetDate and ExposureDate.

DEFINE Incubation NUMERIC
ASSIGN Incubation = OnsetDate  - ExposureDate

In this example, Incubation is only calculated during current dataset processing. It is calculated for each record and may be used similar to a dataset variable in procedures (i.e., TABLES, FREQ, and GRAPH). Prior to and after processing a dataset, Incubation will have a “missing” value, although it could be assigned a value with another statement (e.g., Incubation = 999).

The value is calculated each time a record that meets the conditions of SELECT is read from the dataset. Any legal expression can be used that combines functions or literal values and operators (i.e., &, +, -, *, /, ^, and MOD). Boolean expressions are not supported in assign commands. Standard variables that depend on database fields must be saved to a table using WRITE before they can be edited using LIST UPDATE.

Comments
Temporary variables must be defined before being used and will accept any type of data (i.e., text, numeric, or date). Once they have been assigned a non-missing value or an expression, their type cannot change.
If an attempt is made to assign an invalid expression to a variable, it retains any previous assignment.

Examples
To try the code example below, copy and paste the code example into the Classic Analysis Program Editor and click Run Commands.
The ASSIGN command is used to assign values to defined variables and database variables. Note that literal values (e.g., 42, other variables, and functions) can be used on the right side of the = operator.

READ {.\Projects\Sample\Sample.prj}:Surveillance
DEFINE State TEXTINPUT 
ASSIGN City = "Atlanta" 
ASSIGN State = "GA" 
ASSIGN Address = City & ", " & State 
DEFINE Now DATEFORMAT 
ASSIGN Now = SYSTEMTIME 
DEFINE Duration NUMERIC 
ASSIGN Duration = YEARS(01/01/1998, ReportDate) 
DEFINE Ill YN 
ASSIGN Ill = (-) 
ASSIGN Age = 42 
ASSIGN Occupation = "Doctor" 
LIST Address City State Duration Now Ill Occupation Age 
GRIDTABLE
Page last reviewed: September 16, 2022, 12:00 pm