• <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
      • 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
        • compare Function
        • compareNoCase Function
        • Concat Function
        • String Concatenation Operator
        • Edit Function
        • GetBuffer Function
        • Length Function
        • maketext Function
        • Message Formatting Options
        • Pos Function
        • PosChar Function
        • RegExMatch Function
        • Replace Function
        • StartsWith Function
        • Strip Function
        • ToLower Function
        • ToNumber Function
        • ToUpper Function
      • 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>

Length Function

Format
i = length(string_expression);
Description
The function length calculates the length of an alphanumeric string_expression. If the string is a dictionary item, the value returned is the length of the item. If it the string is the result of a function, the value returned is the length of the string returned by the function.
Return Value
The function returns the length of the string as an integer value. If using an alpha variable or a dictionary item, you may want to strip the string before calculating its length.
Example
alpha (30) NAME = "John Henry";
length(NAME);                   // returns 30
length(strip(NAME));            // returns 10
Uses on List and Array Objects
The length function also operates on List and Array objects. When applied to a List, it returns the number of elements in the List. When applied on an Array, it returns the size of an Array dimension.
Format
i = length(list_name);
i = 
length(array_nameʃ, dimensionʅ);
Examples
Array string usmca_countries(3) = "Canada", "Mexico", "United States";
length(usmca_countries); // returns 3;

// ...

Array AgeSexDeckArray(AGE_VS, SEX_VS);

do numeric age_counter = 1 while age_counter <= length(AgeSexDeckArray, 1)
   
do numeric sex_counter = 1 while sex_counter <= length(AgeSexDeckArray, 2)
       
// ...
    enddo;
enddo;
See also: Array.length Function