specifies a character constant, variable, or expression in which characters are counted.
Tip: | Enclose a literal string of characters in quotation marks. |
specifies a character constant, variable, or expression that initializes a list of characters. COUNTC counts characters in this list, provided that you do not specify the V modifier in the modifier argument. If you specify the V modifier, then all characters that are not in this list are counted. You can add more characters to the list by using other modifiers.
Tip: | Enclose a literal string of characters in quotation marks. |
Tip: | If there are no characters in the list after processing the modifiers, COUNTC returns 0. |
specifies a character constant, variable, or expression in which each non-blank character modifies the action of the COUNTC function. Blanks are ignored. The following characters, in uppercase or lowercase, can be used as modifiers:
adds alphabetic characters to the list of characters.
scans string from right to left, instead of from left to right.
adds control characters to the list of characters.
adds digits to the list of characters.
adds an underscore and English letters ( that is, the characters that can begin a SAS variable name using VALIDVARNAME=V7) to the list of characters.
adds graphic characters to the list of characters.
adds a horizontal tab to the list of characters.
adds lowercase letters to the list of characters.
adds digits, an underscore, and English letters (that is, the characters that can appear in a SAS variable name using VALIDVARNAME=V7) to the list of characters.
processes the charlist and modifier arguments only once, at the first call to this instance of COUNTC. If you change the value of charlist or modifier in subsequent calls, the change might be ignored by COUNTC.
adds punctuation marks to the list of characters.
adds space characters to the list of characters (blank, horizontal tab, vertical tab, carriage return, line feed, and form feed).
trims trailing blanks from string and chars .
Tip: | If you want to remove trailing blanks from only one character argument instead of both (or all) character arguments, use the TRIM function instead of the COUNTC function with the T modifier. |
adds uppercase letters to the list of characters.
counts characters that do not appear in the list of characters. If you do not specify this modifier, then COUNTC counts characters that do appear in the list of characters.
adds printable characters to the list of characters.
adds hexadecimal characters to the list of characters.
Tip: | If modifier is a constant, enclose it in quotation marks. Specify multiple constants in a single set of quotation marks. |
The COUNTC function allows character arguments to be null. Null arguments are treated as character strings with a length of zero. If there are no characters in the list of characters to be counted, COUNTC returns zero.
The COUNTC function counts individual characters in a character string, whereas the COUNT function counts substrings of characters in a character string.
The following example uses the COUNTC function with and without modifiers to count the number of characters in a string.
data test; string = 'Baboons Eat Bananas '; a = countc(string, 'a'); b = countc(string,'b'); b_i = countc(string,'b','i'); abc_i = countc(string,'abc','i'); /* Scan string for characters that are not "a", "b", */ /* and "c", ignore case, (and include blanks). */ abc_iv = countc(string,'abc','iv'); /* Scan string for characters that are not "a", "b", */ /* and "c", ignore case, and trim trailing blanks. */ abc_ivt = countc(string,'abc','ivt'); run; options pageno=1 ls=80 nodate; proc print data=test noobs; run;
The SAS System 1 string a b b_i abc_i abc_iv abc_ivt Baboons Eat Bananas 5 1 3 8 16 11