SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
valleet
Calcite | Level 5

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

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

3 REPLIES 3
Loko
Barite | Level 11

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;
valleet
Calcite | Level 5

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

Loko
Barite | Level 11

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 .

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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