Newsgroups: bit.listserv.sas-l
Date:         Thu, 10 Sep 1992 18:18:15 -0400
Reply-To:     "Paul A. Thompson" <pat@po.CWRU.Edu>
From:         "Paul A. Thompson" <pat@PO.CWRU.EDU>
Subject:      Re: numbers in SAS
Comments: To: KLASSEN%UVVM.BITNET@VTVM2.CC.VT.EDU
Comments: cc: sas-l@vtvm2.cc.vt.edu

Well, this rather simple discussion has certainly gotten quite stimulating,
if you are a nerd (I am a nerd).  Let me summarize:

1. The manual suggests not using shorter lengths for non-integers

2. There will be no noticable differences between an ANOVA using
   LENGTH = 8 variables and LENGTH = 7 variables.

3. There are important exceptions to point 2.
   Mr./Dr. Klassen has provided the exception, in his discussion
   of testing for equality for decimal variables.  He notes:

>Only a naive user of computers should expect a line of code like:
>     IF A EQ .1 THEN ...
>to actually perform what the user intended!
>(I exclude symbolic-manipulation packages like MAPLE and REXX,
>which store all numbers as indefinite-precision strings,
>rather than as finite-precision values.)
>
>A user who codes the above will soon learn that this should be coded as:
>    IF  (A-0.1) < 1.0E-5  THEN PUT 'Close enough for jazz!'
>and that the statement:
>    DO X=0.0 to 100.0 by 0.01
>can produce "interesting" results. :-)

IMHO, the need for these elaborate IF statements may be BECAUSE of the use
of the LENGTH < 8.  That is, short length variables necessitate more
complex IF statements.  Examine these results, run on PC SAS, Version 6.04:

  132    data chk;
  133         length val vam 8;
  134         val=.3;
  135         vam=.3;
  136    run;
NOTE: The data set WORK.CHK has 1 observations and 2 variables.
NOTE: The DATA statement used 3.00 seconds.
  137    data chk;
  138         set chk;
  139         if (val = .3)  then put "val = .3";
  140         else                put "val^= .3";
  141         if (vam = val) then put "val = vam";
  142         else                put "val^= vam";
  143    run;
val = .3
val = vam
NOTE: The data set WORK.CHK has 1 observations and 2 variables.
NOTE: The DATA statement used 4.00 seconds.
  144    data chk;
  145         length val vam 7;
  146         val=.3;
  147         vam=.3;
  148    run;
NOTE: The data set WORK.CHK has 1 observations and 2 variables.
NOTE: The DATA statement used 2.00 seconds.
  149    data chk;
  150         set chk;
  151         if (val = .3)  then put "val = .3";
  152         else                put "val^= .3";
  153         if (vam = val) then put "val = vam";
  154         else                put "val^= vam";
  155    run;
val^= .3
val = vam
NOTE: The data set WORK.CHK has 1 observations and 2 variables.
NOTE: The DATA statement used 3.00 seconds.

   The point of these little examples is that the shorter lengths do lose
something.  Here is what is going on:
1. SAS takes the variable VAL and compares it against the value ".3".  However,
   the value ".3" must also be represented as a variable - the comparison is
   done from one variable to another.  If the variables have the
   same length (8 for the actual variable, 8 for the variable which
   represents the constant), the comparison is done with equal precision
   and produces the expected result.  When the length for the actual variable
   is less than the variable which represents the constant, the things
   being compared are not at the same precision, and the incorrect result
   (that following line 155) results.

   Note that the comparison between the two variable (val and vam, after 155)
   do compare equal.  That is because their imperfect representation
   of the value ".3" is imperfect to the same degree.

2. If you routinely use short lengths, you will probably find lots of
   these inconsistent results.  You will then develop more complex,
   error proof approaches to do if statements, methods which (IMHO) are not
   routinely needed.

So my conclusion is that consistent lengths produce consistent results.
The problem is NOT THE PROBLEM OF THE IMPERFECT REPRESENTATION of
decimals in a binary coding - this is a given.  The real problem is
DIFFERING LEVELS of IMPERFECT REPRESENTATION.  If you use different lengths
your imperfect representations will be different.  If you use the
same length all around, your imperfect representations will be consistent,
and USUALLY yield the correct result.

In my data center, when we find IF statements which do not work as
expected, we almost always find LENGTH problems.

--
Paul Thompson, Ph.D.  |  Department of Psychiatry  |  (216) 844-7463
Case Western Reserve University  | Cleveland, OH  44106
------------------------------------------------------------------------------
When I hear "family values," I reach for my revolver. - paraphrasing Trotsky
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU