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 .

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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