COUNTC Function


COUNTC Function

Counts the number of specific characters that either appear or do not appear within a character string that you specify

Category: Character

Syntax

COUNTC ( string,characters < ,modifiers >)

Arguments

string

  • specifies a character constant, variable, or expression in which characters are to be counted.

  • Tip: Enclose a literal string of characters in quotation marks.

characters

  • is a character constant, variable, or expression that specifies one or more characters to count in string .

  • Tip: Enclose a literal string of characters in quotation marks.

modifiers

  • is a character constant, variable, or expression that specifies one or more modifiers. The following modifiers can be in uppercase or lowercase:

    i

    ignores character case during the count. If this modifier is not specified, COUNTC only counts characters with the same case as the characters in characters .

    o

    processes characters and modifiers only once, at the first call to this instance of COUNTC. Consequently, if you change the value of characters or modifiers in subsequent calls, the change is ignored by COUNTC.

    t

    trims trailing blanks from string and characters .

    v

    counts only the characters that do not appear in characters .

  • Tip: If the modifier is a constant, enclose it in quotation marks. Specify multiple constants in a single set of quotation marks. Modifier can also be expressed as a variable or an expression that evaluates to one or more constants.

Details

The COUNTC function searches string for all occurrences of the specified characters and returns the count for all of those characters. If none are found, COUNTC returns a value of 0.

Comparisons

The COUNTC function counts individual characters in a character string, whereas the COUNT function counts substrings of characters in a character string.

Examples

The following SAS statements produce these results:

SAS Statements

Results

   xyz='Baboons Eat Bananas     '; howmanya=countc(xyz,'a'); put howmanya;   

5

   xyz='Baboons Eat Bananas     '; howmanyb=countc(xyz,'b'); put howmanyb;   

1

   howmanyb_i=countc('Baboons Eat Bananas     ','b','i'); put howmanyb_i;   

3

   xyz='Baboons Eat Bananas     '; howmanyab_i=countc(xyz,'ab','i'); put howmanyab_i;   

8

   variable1='Baboons Eat Bananas     '; variable2='ab'; variable3='iv'; howmanyab_iv=countc(variable1,variable2,variable3); put howmanyab_iv;   

16

   expression1='Baboons ''Eat Bananas     '; expression2=trim('ab     '); expression3=compress('i     ''v''     t'); howmanyab_ivt=countc(expression1,expression2,expression3); put howmanyab_ivt;   

11

See Also

Functions:

  • 'COUNT Function' on page 468

  • 'FINDC Function' on page 535

  • 'INDEXC Function' on page 590

  • 'VERIFY Function' on page 882




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net