Solved
New Contributor
Posts: 3

# How to compare two character fields to check if they are equal

Hi All,

I would like to check if 2 addresses are equal. I am using Compare function but for the ones I assume they are equal instead of 0 I get a number.

here is my example:

 Add1 Add2 11 JANE ST 11 JANE ST

compare(Add1,Add2) but instread of 0 it SAS EG gives me 5. I checked in Excel and Excel resut is these 2 are equal.

Accepted Solutions
Solution
‎11-09-2017 11:56 PM
New Contributor
Posts: 3

## Re: How to compare two character fields to check if they are equal

Thank you Reeza for replying quickly.

I changed the format to \$hex32. and I see they are different as below in the 9th postion from left and some other letters as well inside the string.

 Add1 Add2 11 JANE ST 11 JANE ST 3131204A616E65205374202020202020 3131204A414E45205354202020202020

I have not with HEX format before and not sure if I've got your advice right and also I dont know how to recognise if it is because of space or not. So could you please let me know how I can remove potential space inside the text if there is any solution?

Regards,

All Replies
Super User
Posts: 24,012

## Re: How to compare two character fields to check if they are equal

Please provide a reproducible sample so that we replicate your issue.

If you can't replicate it, it's an issue with your data. Try looking at the data with a HEX format to see if its different.

You may have spaces in one and a different invisible character in others.

Here's an example of how to use the HEX format to see the difference

``````data class;
set sashelp.class;

put name \$hex32.;
run;``````

Solution
‎11-09-2017 11:56 PM
New Contributor
Posts: 3

## Re: How to compare two character fields to check if they are equal

Thank you Reeza for replying quickly.

I changed the format to \$hex32. and I see they are different as below in the 9th postion from left and some other letters as well inside the string.

 Add1 Add2 11 JANE ST 11 JANE ST 3131204A616E65205374202020202020 3131204A414E45205354202020202020

I have not with HEX format before and not sure if I've got your advice right and also I dont know how to recognise if it is because of space or not. So could you please let me know how I can remove potential space inside the text if there is any solution?

Regards,

New Contributor
Posts: 3

## Re: How to compare two character fields to check if they are equal

it was fixed by COMPARE(TRIM(UPCASE(Add1 )), TRIM(UPCASE( Add2)))

thanks again Reeza

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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