Epi Info™ User Guide

Command Reference


Analysis Commands: Sort

Description
This command allows a sequence to be specified for records to appear in LIST, GRAPH, and WRITE commands. If no variable names are specified after the SORT command, the current sort is cleared, and subsequent output is in the order of the original table. If one field is given, records are sorted using that field as the “key”. If more than one field is given, records are put in order by the first variable, then by each subsequent variable in the order they appear in the list.

Syntax
SORT <field> {DESCENDING}

  • <field> represents the key field for sorting.
  • DESCENDING indicates that the sort order is descending; if not specified, ascending order is used.

Comments
The DESCENDING key word must follow the field name to be sorted in descending order.  If more than one field is included in the sort order, each field must be followed by the DESCENDING key word for them to be sorted in descending order.

Examples
Example 1:  Data are sorted by Age in ascending order.  After sorting, a grid table displays the list of fields.

READ  {.\Projects\Sample\Sample.prj}:Oswego 
SORT Age 
LIST Age Sex Ill GRIDTABLE

Example 2:  Data are sorted by Age in descending order.  If two or more records have the same value for Age, the records are sorted by Ill in descending order.   If two or more records have the same value for Ill, the records are sorted by Sex in descending order.  After sorting, a grid table displays the list of fields.

READ  {.\Projects\Sample\Sample.prj}:Oswego
SORT Age DESCENDING Ill DESCENDING Sex DESCENDING 
LIST Age Ill Sex GRIDTABLE