Searches a string for any character in a list of characters.
Category: | Character |
Restriction: | I18N Level 1 functions should be avoided, if possible, if you are using a non-English language. The I18N Level 1 functions might not work correctly with Double Byte Character Set (DBCS) or Multi-Byte Character Set (MBCS) encodings under certain circumstances. |
Tip: | Use the KINDEXC Function in SAS National Language Support (NLS): Reference Guide instead to write encoding independent code. |
is a character constant, variable, or expression that specifies the character string to be searched.
Tip | Enclose a literal string of characters in quotation marks. |
is an optional constant, variable, or character expression that initializes a list of characters. FINDC searches for the characters in this list provided that you do not specify the K modifier in the modifier argument. If you specify the K modifier, FINDC searches for all characters that are not in this list of characters. You can add more characters to the list by using other modifiers.
is an optional character constant, variable, or expression in which each character modifies the action of the FINDC function. The following characters, in upper- or lowercase, can be used as modifiers:
is ignored.
adds alphabetic characters to the list of characters.
searches from right to left, instead of from left to right, regardless of the sign of the startpos argument.
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.
ignores character case during the search.
searches for any character that does not appear in the list of characters. If you do not specify this modifier, then FINDC searches for any character that appears in 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 the modifier arguments only once, rather than every time the FINDC function is called. Using the O modifier in the DATA step (excluding WHERE clauses), or in the SQL procedure can make FINDC run faster when you call it in a loop where the charlist and the modifier arguments do not change.
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).
adds uppercase letters to 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, then 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. |
data _null_; string = 'Hi, ho!'; charlist = 'ho'; j = 0; do until (j = 0); j = findc(string, charlist, j+1, "i"); if j = 0 then put +3 "That's all"; else do; c = substr(string, j, 1); put +3 j= c=; end; end; run;
data _null_; string = 'Hi, ho!'; charlist = 'hi'; j = 0; do until (j = 0); j = findc(string, charlist, "k", j+1); if j = 0 then put +3 "That's all"; else do; c = substr(string, j, 1); put +3 j= c=; end; end; run;
data _null_; whereishi_i=0; do until(whereishi_i=0); variable1='Hi there, Ian!'; variable2='hi'; variable3='i'; whereishi_i=findc(variable1,variable2,variable3,whereishi_i+1); if whereishi_i=0 then put “The End”; else do; whatfound=substr(variable1,whereishi_i,1); put whereishi_i= whatfound=; end; end; run;
data _null_; whereishi_t=0; do until(whereishi_t=0); expression1='Hi there, '||'Ian!'; expression2=kscan('bye or hi',3)||' '; expression3=trim('t '); whereishi_t=findc(expression1,expression2,expression3,whereishi_t+1); if whereishi_t=0 then put “The End”; else do; whatfound=substr(expression1,whereishi_t,1); put whereishi_t= whatfound=; end; end; run;
data _null_; whereishi_iv=0; do until(whereishi_iv=0); xyz='Hi there, Ian!'; whereishi_iv=findc(xyz,'hi',whereishi_iv+1,'iv'); if whereishi_iv=0 then put “The End”; else do; whatfound=substr(xyz,whereishi_iv,1); put whereishi_iv= whatfound=; end; end; run;
whereishi_iv=3 whatfound= whereishi_iv=4 whatfound=t whereishi_iv=6 whatfound=e whereishi_iv=7 whatfound=r whereishi_iv=8 whatfound=e whereishi_iv=9 whatfound=, whereishi_iv=10 whatfound= whereishi_iv=12 whatfound=a whereishi_iv=13 whatfound=n whereishi_iv=14 whatfound=! The End