**Date:** Tue, 21 Jul 2009 11:19:58 -0500
**Reply-To:** Joe Matise <snoopy369@GMAIL.COM>
**Sender:** "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
**From:** Joe Matise <snoopy369@GMAIL.COM>
**Subject:** Re: What is the value of variable x?
**In-Reply-To:** <482249F865060740AE33815802042D2F04E94D9D@LTA3VS012.ees.hhs.gov>
**Content-Type:** text/plain; charset=ISO-8859-1
Even more fun this way:

data a;
format x hex16.;
x=0.7;
x+.1;
x+.1;
x+.1;
if x=1 then put "=== " x "equals to 1.";
else put "=== " x "does not equal to 1.";
run;

data b;
format x hex16.;
x=0.7;
x+.1;
x+.1;
x+.1;
x+.0000000000000001;
if x=1 then put "=== " x "equals to 1.";
else put "=== " x "does not equal to 1.";
run;

There are several threads that go into numerics at length... in general, the
issue is that a number (say, .7) cannot be expressed as a power of 2, so
there is a slight error introduced at that point; that error causes the
number to not quite be correct. 3FFFEFFFFFFFFFFF is a tiny bit less than 1,
as a result.

It's like if you were in base 10, and said:
x=(1/3);
x+(1/3);
x+(1/3);
your result would be
.999999999999999999999999
not 1, since (1/3) cannot be represented exactly in base 10 (ever, no matter
what the precision is). Same issue here, but base 10 vs binary (so the
'problem numbers' are different). Using FUZZ you can tell SAS to ignore
tiny errors like that:

data c;
x=0.7;
x+.1;
x+.1;
x+.1;
if fuzz(x)=1 then y=1;
else y=0;
if y=1 then put "=== " x "equals to 1.";
else put "=== " x "does not equal to 1.";
run;

If you run it out and put x= after each line, you'll get:
x=3FE6666666666666
x=3FE9999999999999
x=3FECCCCCCCCCCCCC
x=3FEFFFFFFFFFFFFF

Notice how similar this is to the 1/3 problem?

-Joe

On Tue, Jul 21, 2009 at 9:46 AM, Fehd, Ronald J. (CDC/CCHIS/NCPHI) <
rjf2@cdc.gov> wrote:

> what you see is base 10 representation
> but your computer is talking in bits, nibbles, and bytes
>
> http://www.sascommunity.org/wiki/Numeric_representation_issues_in_SAS
>
> you can add this phrase to your put statements
> x= hex16.
>
> which will show you the underlying numerical representation
>
> Ron Fehd the bitness business maven CDC Atlanta GA USA RJF2 at cdc dot
> gov
>
> > -----Original Message-----
> > From: owner-sas-l@listserv.uga.edu
> > [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Pobel
> > Sent: Tuesday, July 21, 2009 4:59 AM
> > To: sas-l@uga.edu
> > Subject: What is the value of variable x?
> >
> > Hi everyone,
> >
> > Please see the following two data steps:
> >
> > data a;
> > x=0.8;
> > x+.1;
> > x+.1;
> > if x=1 then put "=== " x "equals to 1.";
> > else put "=== " x "does not equal to 1.";
> > run;
> >
> > ------------------------------------
> > log:
> > === 1 equals to 1.
> > ------------------------------------
> >
> > data b;
> > x=0.7;
> > x+.1;
> > x+.1;
> > x+.1;
> > if x=1 then put "=== " x "equals to 1.";
> > else put "=== " x "does not equal to 1.";
> > run;
> >
> > ----------------------------------------
> > log:
> > === 1 does not equal to 1
> > ----------------------------------------
> >
> > Can anyone tell me why? How exactly the value of x is processed?
> >
> > Thanks in advance!
> >
> > -Pobel
> >
> >
>