Dear all,
I am trying to use the use the find() function in SAS Enterprise 5.1.
It does not work as specified in all the literature I found on the web. It is only able to find perfect matches between two
strings. For instance, it return 1 on find(col1,col2) when col1 contains "CORK" and col2 "CORK", but 0 when col1 contains
"ICORK" and col2 contains "CORK".
Can someone explain why find() has the behavior ?
Thanks,
Thierry
Hello,
Providing the substring (in your ex. col2) in the form of a variable means SAS adds the spaces which fill in the variable until thje length provided (in your example 20).
Adjusting the code to test = find(col1,trim(col2)); will do it .
Hello,
It works as explained in the documentation:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002267763.htm
The following example returns z=2 in the log.
data _null_;
col1='ICORK';
col2='CORK';
z=find(col1,col2);
put z=;
run;
Here is my test code:
data testFile;
length col1 $20 col2 $20;
input col1 $ col2 $;
datalines;
ICORK CORK
CORK DUBLIN
;
run;
data testFind;
set testFile;
put col1= col2=;
test = find(col1,col2);
run;
and is find() does not find CORK in ICORK
Do you have an idea why?
Thansks,
Thierry
Hello,
Providing the substring (in your ex. col2) in the form of a variable means SAS adds the spaces which fill in the variable until thje length provided (in your example 20).
Adjusting the code to test = find(col1,trim(col2)); will do it .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.