• <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
      • Multiple Occurrence Functions
        • Average Function
        • Count Function
        • CurOcc Function
        • Delete Function
        • GetOccLabel Function
        • Insert Function
        • Max Function
        • MaxOcc Function
        • Min Function
        • NOccurs Function
        • Seek Function
        • SeekMax Function
        • SeekMin Function
        • SetOccLabel Function
        • SOccurs Function
        • Sort Function
        • Sum Function
        • Swap Function
        • TotOcc Function
      • 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>

Seek Function

Format
i = seek (multiple_item condition[,numeric_expr]);
Description
The seek function returns the occurrence number of the first item in a multiply-occurring item that satisfies the given condition. If numeric_expr is included, the function starts searching the multiply-occurring record for a true condition starting at occurrence numeric_expr. If an @ symbol precedes the numeric_expr, the function searches for the nth occurrence of the condition.
Return Value
The function returns the occurrence number of an item that meets the condition. If no item is found it returns 0.
Example 1
PROC PERSON_ROSTER

numeric femaleIndex = seek(SEX = 2);

while femaleIndex do
   
write("Person #%d is a female with name '%s'",femaleIndex,NAME(femaleIndex));
    femaleIndex = 
seek(SEX = 2,femaleIndex + 1);
enddo;
Example 2
numeric secondSpouse = seek(RELATIONSHIP = 2,@2);
Example 3
numeric firstFemaleOver15 = seek(SEX=2 and AGE >= 15); // multiple conditions can be given
See also: Count Function, Has Operator, SeekMax Function, SeekMin Function