While I have used the SAS FIND() function frequently, that is not the case for the similarly named FINDW() (find word) function. Taking advice from the 1980s band Devo, a problem came along and I was ready to whip it, whip it good!
A pangram is a unique sentence that contains all the leters of the alphabet at least once. The name comes from the Greek root words pan, meaning "all," and gram, meaning "something written or recorded". The best-known English pangram is "The quick brown fox jumps over the lazy dog" and that is what I will use to test the issue.
The FIND() function returns the starting position of the substring of characters so it can find both Quick and Qui. It is important to note that the 3rd parameter in FIND that uses an 'i' modifier to ignore the case of the characters - upper and lower are treated the same.
Now that we know how the FIND() function works, you would think that FINDW() would do the same - that is the 3rd parameter just needs a 'i' to ignore the case and it will work on full words not a substring. That is not the case for FINDW(), see the differnce between a_findw and a_findw2 that can find the word 'Quick'.
There are times I want an exact match vs a substring match and now I can see the differences - problem whiped - err solved.
data test; str = "The quick brown fox jumps over the lazy dog"; a_find = find(str, "Quick", 'i'); /* found at position 5 */ a_findw = findw(str, "Quick", 'i'); /* not found */ a_findw2 = findw(str, "Quick", ' ', 'i'); /* found at position 5 */ b_find = find(str, 'Qui', 'i'); /* found at position 5 */ b_findw2 = findw(str, 'Qui', ' ', 'i'); /* not found - no word named Qui */ run;
Should you think this post has gone to the dogs, please consider just as in SAS there are many ways to solve a problem there too are alternate ways to whip it, whippet good!
No comments:
Post a Comment