Epi Info™ User Guide

Command Reference


Analysis Commands: WRITE

Description
The WRITE command sends records to an output table or file in the specified format. Specifications include which variables are written, variable order, and the type of file to be written.

Syntax
WRITE <METHOD> {<output type>} {<project>:}table {[<variable(s)>]}
WRITE <METHOD> {<output type>} {<project>:}table * EXCEPT {[<variable(s)>]}

  • <METHOD> represents either REPLACE or APPEND
  • <project> represents the path and filename of the output.
  • <variable(s)> represents one or more variable names.
  • <output type> represents the following allowable outputs:
Database Type Specifier Element
Epi Info 7 ” Epi Info 7 <path:<table>
MS Access 97-2003 MS Access 97-2003 <path>
MS Access 2007 MS Access 2007 <path>
Excel 97-2003 MS Access 97-2003 <path>
Excel 2007 MS Access 2007 <path>
SQL Server Server Name & Database Name
Text (Delimited) “Text” <path>

Comments
Records deleted in Enter or selected in Classic Analysis are handled as in other Analysis commands. Defined variables may be written to allow you to create a new Epi Info 7 file to make permanent changes. Unless explicitly specified, global and permanent variables will not be written.

To write only selected variables, the word EXCEPT may be inserted to indicate all variables except those following EXCEPT.

If the output file specified does not exist, the WRITE command will attempt to create it.

Either APPEND or REPLACE must be specified to indicate that an existing file/table by the same name will be erased or records will be appended to the existing file/table. If not all of the fields being written match those in an existing file during an APPEND, the unmatched fields are added to the output table.

Examples
Example 1: The Oswego data table (75 records) from Sample.PRJ is written to a database called SampleOutput. The destination table name is called Oswego_1. The second READ command reads the newly-created data table.

READ {.\Projects\Sample\Sample.prj}:Oswego 
WRITE REPLACE "Epi7" {Provider=Microsoft.Jet.OLEDB.4.0; Data Source=.\Projects\Sample\SampleOutput.mdb} : Oswego_1 * 
READ {.\Projects\Sample\SampleOutput.mdb}:Oswego_1

Example 2: The Oswego data table (75 records) from Sample.PRJ is written to a database called SampleOutput three times. The APPEND method ensures that each WRITE command appends the entire data set several times. After all three WRITE commands have been run, the Oswego_2 table inside SampleOutput.mdb will contain 225 records.

READ {.\Projects\Sample\Sample.prj}:Oswego 
WRITE APPEND "Epi7" {Provider=Microsoft.Jet.OLEDB.4.0; Data Source=".\Projects\Sample\SampleOutput.mdb"} : OSWEGO_2 * 
WRITE APPEND "Epi7" {Provider=Microsoft.Jet.OLEDB.4.0; Data Source=".\Projects\Sample\SampleOutput.mdb"} : OSWEGO_2 * 
WRITE APPEND "Epi7" {Provider=Microsoft.Jet.OLEDB.4.0; Data Source=".\Projects\Sample\SampleOutput.mdb"} : OSWEGO_2 * 
READ  {.\Projects\Sample\SampleOutput.mdb}:OSWEGO_2

Example 3: This example shows how to make defined variables into permanent database variables. The Oswego data table from Sample.PRJ is written to a database called SampleOutput. Notice that the defined variable IncubationTime does not exist in Sample.PRJ, but after the WRITE command has executed, it is now a part of the newly-created data table Oswego_3.

READ {.\Projects\Sample\Sample.prj}:Oswego 
DEFINE IncubationTime NUMERIC 
ASSIGN IncubationTime = HOURS(TimeSupper, DateOnset)
LIST IncubationTime 
WRITE REPLACE "Epi7" {Provider=Microsoft.Jet.OLEDB.4.0; Data Source=".\Projects\Sample\SampleOutput.mdb"} : OSWEGO_3 * 
READ {.\Projects\Sample\SampleOutput.mdb}:OSWEGO_3 
LIST * 
GRIDTABLE

Example 4: The records from the Oswego Form in the Sample database are exported to an Excel spreadsheet. By specifying age, sex, and incubation time in the WRITE command, only those variables will be exported. This example may not work if Microsoft Excel is not installed on the computer.

READ {.\Projects\Sample\Sample.prj}:Oswego 
DEFINE IncubationTime 
ASSIGN IncubationTime = HOURS(TimeSupper, DateOnset) 
WRITE REPLACE "Epi7" {Provider=Microsoft.Jet.OLEDB.4.0; Data Source=".\Projects\Sample\Oswego.xls";Extended  Properties="Excel 8.0;HDR=Yes;IMEX=1"} : OSWEGO_1 Age Sex IncubationTime * 
READ  {.\Projects\Sample\Oswego.xls}:[OSWEGO_1$] 
LIST *  
GRIDTABLE

Example 5: The records from the Oswego Form in the Sample database are exported to a text file.

READ {.\Projects\Sample\Sample.prj}:Oswego 
WRITE REPLACE "Epi7" {Provider=Microsoft.Jet.OLEDB.4.0; Data Source=".\Projects\Sample "; Extended Properties="text;HDR=Yes;FMT=Delimited"} : [OSWEGO#txt] *