SAS String Function FIND( )
<< Go Back to SAS String Functions
As name suggests SAS Find () function is basically used to find if given string in interest is present in the master string. Find function returns the position of sub string in the target string if it’s present within; else it returns 0.
Find function provides the added facilities to users like; one can give the starting position to start finding; can prompt to ignore the CASE, give the direction of search, ignoring the trailing blanks etc.
This has been demonstrated below;
SAS FIND( ) function:
SYNTAX: FIND (master_string, search_string, <’modifiers’>,<starting_position>);
Example: SAS FIND( ) Function
SAS Code:
data temp;
pos_1 = find ("Sachin Tendulkar","kar");
pos_2 = find ("Sachin Tendulkar","ten");
pos_3 = find ("Sachin Tendulkar","ten","i");
pos_4 = find ("Sachin Tendulkar","kar",99);
run;
proc print data = temp;
run;
PROC PRINT OUTPUT :
* Please note this code has compiled on SAS 9.2 Platform.
It’s worth to note that;
In second statement
pos_2 = find ("Sachin Tendulkar","ten");
Though “ten” is part of first string; as we haven’t specified a case insensitive search; FIND() function returned 0.
In third statement
pos_3 = find ("Sachin Tendulkar","ten","i");
It worked as expected; as we mentioned the search to case insensitive; by specifying in the third argument.
In Fourth Statement
pos_4 = find ("Sachin Tendulkar","kar",99);
As we specified invalid start position; it returned 0.