DATA Step, Macro, Functions and more

find function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

find function

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

 


Accepted Solutions
Solution
‎12-28-2016 07:05 AM
Super Contributor
Posts: 305

Re: find function

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 .

View solution in original post


All Replies
Super Contributor
Posts: 305

Re: find function

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;
Occasional Contributor
Posts: 6

Re: find function

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

Solution
‎12-28-2016 07:05 AM
Super Contributor
Posts: 305

Re: find function

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 .

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 507 views
  • 0 likes
  • 2 in conversation