• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
        • List Statement
        • List.add Function
        • List.insert Function
        • List.seek Function
        • List.remove Function
        • List.removeDuplicates Function
        • List.removeIn Function
        • List.clear Function
        • List.length Function
        • List.show Function
        • List.sort Function
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

List.sort Function

Format
b = list_name.sort(ʃascending ‖ descendingʅ);
Description
The List.sort function sorts the values within a List. An optional argument, ascending or descending, allows for the specification of the sort order. If not specified, the default sort order is ascending. String values are sorted in case sensitive order, so "c" is recognized as different from "C".
Return Value
The function returns a logical value of 1 (true). If the List is read-only, the function returns default.
Example
List string children_names;

for POPULATION_RECORD where HH_RELATIONSHIP = 3 do
    children_names.
add(HH_NAME);
enddo;

children_names.
show("Children in Household (before sort)");
// possible results: Betty, Ellen, Charlene, Donna, Danny, Donnie, Cindy, Elaine

children_names.
sort();
children_names.
show("Children in Household (after ascending sort)");
// possible results: Betty, Charlene, Cindy, Danny, Donna, Donnie, Elaine, Ellen

children_names.
sort(descending);
children_names.
show("Children in Household (after descending sort)");
// possible results: Ellen, Elaine, Donnie, Donna, Danny, Cindy, Charlene, Betty
See also: List Object, List.show Function