BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vkabdwal
Obsidian | Level 7

Find function is giving unexpected results.

 

Output:

vkabdwal_0-1638862336987.png

 

I am expecting 1 as the answer here but getting 0.

 

In text format output for last three fields:  
 full_rating:  "Action: New Rating (Mar-07-2018)
From ""-"" to ""BB-"""

 

b_rating:   "Action: New Rating (Mar-07-2018)
From ""-"" to ""BB-"""

 

find:  0

 

Code: 

proc sql;
create table old_match_change as

select *, find(compress(upcase(full_rating),' ():"'), compress(upcase(b_rating),' ():"')) as find
from old_match 
where find(compress(upcase(full_rating),' ():"'), compress(upcase(b_rating),' ():"'))=0;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

If you want to get rid of the line breaks, use 'c' (remove control characters) as the third parameter to COMPRESS, e.g.:

proc sql;
create table old_match_change as

select *, find(compress(upcase(full_rating),' ():"','c'), compress(upcase(b_rating),' ():"','c')) as find
from old_match 
where find(compress(upcase(full_rating),' ():"','c'), compress(upcase(b_rating),' ():"','c'))=0;
quit;

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

You seem to have a line break. Compress non-printable characters too a lines breaks can take different forms.

vkabdwal
Obsidian | Level 7
What solution you suggest? Please elaborate a bit.
ChrisNZ
Tourmaline | Level 20

The compress function allows you to eliminate non-printable characters. See the documentation.

Note also that the find function allows case insensitive comparisons, so you needn't use the upcase function here. Again see the documentation.

ChrisNZ
Tourmaline | Level 20

Compare the lengths of the compressed strings. If they are the same, compare their value printed with the $hex. format.

s_lassen
Meteorite | Level 14

If you want to get rid of the line breaks, use 'c' (remove control characters) as the third parameter to COMPRESS, e.g.:

proc sql;
create table old_match_change as

select *, find(compress(upcase(full_rating),' ():"','c'), compress(upcase(b_rating),' ():"','c')) as find
from old_match 
where find(compress(upcase(full_rating),' ():"','c'), compress(upcase(b_rating),' ():"','c'))=0;
quit;
vkabdwal
Obsidian | Level 7

Did the trick. Thanks @s_lassen @ChrisNZ for you valuable inputs.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 6 replies
  • 1346 views
  • 3 likes
  • 3 in conversation