• <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
        • ABS Function
        • CMCode Function
        • CountNonSpecial Function
        • Exp Function
        • High Function
        • Inc Function
        • Int Function
        • Log Function
        • Low Function
        • Random Function
        • RandomIn Function
        • Round Function
        • Seed Function
        • Sqrt Function
        • Set Behavior SpecialValues Statement
      • 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>

CountNonSpecial Function

Format
i = countnonspecial(item_name ‖ record_name ‖ array_name ‖ numeric_expressionʃ, ...ʅ);
Description
The function countnonspecial counts the number of non-special values within the passed arguments. Special arguments include missing, refused, notappl, and default. The function can receive multiple numeric arguments, including items, records, arrays, and numeric expressions. This function can greatly simplify some programming tasks; for example, the following two lines of code are the same:
if countnonspecial(RELATIONSHIP, SEX, AGE) = 3 then

if not special(RELATIONSHIP) and not special(SEX) and not special(AGE) then
If an Array object is passed, the function will count the non-special values among all the values in the array. For a multiply occurring item or record, to count the non-special values for all the items or records instead of just the current occurrence, include (*) after the item or record name.
The countvalid function is a synonym for this function.
Example 1
PROC GLOBAL

   
numeric tempVal = notappl;
   
Array tempArray(2, 3) = 1, 2, 3, notappl, missing, default;

PROC EXAMPLE

   
countnonspecial(5, tempVal, default, 28 + 31, 3 / 0); // returns 2

    tempVal = 
0.123456789;
   
countnonspecial(5, tempVal, default, 28 + 31, 3 / 0); // returns 3

   
countnonspecial(5, tempVal, default, 28 + 31, 3 / 0, tempArray); // returns 6

    tempArray(
2, 1) = 0;
   
countnonspecial(5, tempVal, default, 28 + 31, 3 / 0, tempArray); // returns 7
Example 2
// in this example SEX is not on the FERTILITY record
PROC SEX

if SEX <> 2 and countnonspecial(FERTILITY(curocc())) > 3 then
   
errmsg("Sex (%d) is not female but 4+ fertility entries defined so sex changed to female", SEX);
   
impute(SEX, 2);
endif;
Example 3
numeric numDefinedValues = countnonspecial(SEX(*), AGE(*));
numeric numPossibleValues = 2 * totocc(POPULATION);

errmsg("%d% of sex and age values are missing", 100 * ( 1 - ( numDefinedValues / numPossibleValues ) ));
See also: Special Function, Special Values