comparing numberic variables of unequal lengths in SAS


I am reading a text file into SAS.  Field A on the text file is 5 bytes in length.  I am trying to compare it to a  table in SAS where the SAS table has it as 8 bytes in length.  The field has 3 decimal positions.

So even though both variables on the table have the same value i.e. 0.107  I am not getting an equal on the compare.

The text file I am reading in the field looks like this.  It is pipe delimited |0.107|.  Can someone tell me what I can do so that these two fields compare as equal.
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi there morinia,

What you are up against is numeric representation and the imprecision of storing (some) fractional values, and the exact method SAS (in this case) decodes the characters 0 1 0 7 into a value approximately equal to 0.107.
Note here that SAS needs to do a sum af the <digits and multiply by a power of 10> successive times when decoding "0 . 1 0 7" into 0.107.  And the result of summing a series of number can depend on the order that you sum them. Usually it said "due to rounding errors".

By default in SAS, numeric variables are stored in 8 bytes (but you can change that if you want).

Can you check that the column in the table you want to compare it agains is a numeric field.

When you read-in the text file you typically give a numeric informat (say " 5.3 ") which will convert a text field on file into a number.  Can you also check that is the case and you are not using a character format (like $5.)

Then the comparision will work OK if the numbers are integers or involve fractions made up only of sums of negative powers of 2 (eg 0.5, 0.625, 0.75)

Otherwise the FUZZ problem will get you in the end!

To get around that problem use the "COMPFUZZ" function.

COMPFUZZ(a, b)  returns -1 , 0  , 1 depending if  a<b, a=b , a > b where all these comparisions allow for a bit of fuzziness in the comparision.  Check the function reference documentation for more information.
For example -
  if  COMPFUZZ(tableColumnA, fileColumnA) ^= 0 then
                  put "WARNING:  different values detected in case " _N_ tableColumnA=  fileColumnA=  );
                 put  "NOTE: variables are equal (or extremely close in value)l";

Open in new window

If either or both of the  columns (or variables) are character then extra work will be required.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.