Epi Info™ User Guide

Command Reference


Analsysis Commands: DEFINE

Description
This command creates a new variable.

Syntax
DEFINE <variable> (<scope>) (<type indicator>)

  • <variable> represents the name of the variable to be created.
  • <scope> is the level of visibility and availability of the new variable and must be one of the reserved words STANDARD, GLOBAL, or PERMANENT. If omitted, STANDARD is assumed and a type indicator may not be used.
  • <type indicator> is required and cannot be used if <scope> is omitted. <type indicator> is the data type of the new variable and must be one of the following reserved words: NUMERIC, TEXTINPUT, YN, or DATEFORMAT. If omitted, the variable type will be inferred based on the data type of the first value assigned to the variable. However, omitting field type is not recommended. Once field type is defined, the variable type cannot be changed. An error will occur if you attempt to assign data of a different type to the variable.

Comments 
A custom variable defined in Epi Info 7 might not have a predefined data type if the <type indicator> is omitted when the variable is defined. If the variable does not have a predefined type and has not been used, the variable will accept a value in any of the four data types (Text, Number, Date, Yes/No [Boolean]) that is assigned to the variable the first time. Thereafter, the variable takes on the data type of the value assigned and it’s data type cannot be changed. However, omitting field type is not recommended. An error will occur if you attempt to assign data of a different data type. Various functions can be used to manipulate data, changing data type of values to match the data type of the variable. Some of these functions include FORMAT, TXTTONUM, TXTTODATE, and NUMTODATE.

Variable Scope

  • STANDARD variables retain their value only within the current record and are reset when a new record is loaded. Standard variables are used temporarily behaving like other fields in the database. In Classic Analysis, Standard variables lose their values and definitions with each READ statement.
  • GLOBAL variables retain values across related forms and when the program opens a new form, but are removed when the Classic Analysis program is closed. Global variables persist during program execution. Global variables are also used to store values between changes of data source (e.g., when the READ command is used). Global variables in Classic Analysis may not depend directly or indirectly on table fields.
  • PERMANENT variables are stored in the EpiInfo.Config.xml file and retain any value assigned until the value is changed by another assignment or the variable is undefined. Permanent variables are shared among Epi Info 7 programs (i.e., Menu, Enter, Classic Analysis, etc.) and persist even if the computer shuts down. Permanent variables in Classic Analysis may not have values that depend directly or indirectly on table fields. A <prompt/description> created for a permanent variable will exist for one session and must be re-established each time it is used.

Type Indicators

  • TEXTINPUT – Variables of this data type can receive any alpha-numeric characters including symbols and the output of functions (e.g., FORMAT).
  • NUMERIC – Variables of this data type can receive numbers and the output of functions (e.g., TXTTONUM).
  • DATEFORMAT – Variables of this data type can receive date values including the output of functions (e.g., TXTTODATE and NUMTODATE).
  • YN – Variables of this data type can receive the Boolean values of (+) for Yes and (-) for No. Until an assignment is made, YN type variable values are (.) or missing.

Example

READ {.\Projects\Sample\Sample.prj}:Surveillance 
DEFINE  Birthday DATEFORMAT 
ASSIGN Birthday = 01/01/2006 
DEFINE HospitalCode NUMERIC 
ASSIGN HospitalCode = 854 
DEFINE Smoke YN 
ASSIGN Smoke = (+) 
LIST Birthday HospitalCode Smoke