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.

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