• <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
      • General Functions
      • Date and Time Functions
      • External File Functions
        • Clear Function
        • Close Function
        • CountCases Function
        • CurrentKey Function
        • DelCase Function
        • DirCreate Function
        • DirDelete Function
        • DirExist Function
        • DirList Function
        • FileConcat Function
        • FileCopy Function
        • FileCreate Function
        • FileDelete Function
        • FileEmpty Function
        • FileExist Function
        • FileName Function
        • FileRead Function
        • FileRename Function
        • FileSize Function
        • FileTime Function
        • FileWrite Function
        • Find Function
        • Key Function
        • KeyList Function
        • LoadCase Function
        • Locate Function
        • NMembers Function
        • Open Function
        • Retrieve Function
        • Set Access Statement
        • SetFile Function
        • Set First Statement
        • Set Last Statement
        • Write Function
        • WriteCase Function
      • 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>

Key Function

Format
s = key(dictionary_name);
Description
The key function returns a string containing the key of the case currently loaded in the file referenced by dictionary_name. A dictionary key is a single string comprised of the IDs for a case. The key is created using the case's IDs as they existed when the case was last loaded or written..
Return Value
The function returns a string containing the key. If there has been no previous activity on the file and no key has been established, the key function returns a blank string.
Example
// do not output any cases with IDs starting with 04
if key(CENSUS_DICT)[1:2] = "04" then
   
skip case;
endif;
Differences Between key and currentkey
The key and currentkey functions will often return the same key string, but when modifications are made to ID values, the key will not change whereas currentkey will reflect the modifications. For example:
loadcase(DICT_NAME, "0102");

key(DICT_NAME);        // 0102
currentkey(DICT_NAME); // 0102

ID1 = 
99;
ID2 = 
8;

key(DICT_NAME);        // 0102
currentkey(DICT_NAME); // 9908
See also: CurrentKey Function, KeyList Function, Key PFF Attribute, GetCaseLabel Function