The following output shows the results from this example:
Output 4.8 Determining How Many Bytes Are Needed to Store a Number Accurately
Note that the minimum length required for the value 271 is greater than the minimum
required for the value
272. This fact illustrates that it is possible for the largest number
in a range of numbers to require fewer bytes of storage than a smaller number. If
precision is needed for all numbers in a range, you should obtain the minimum length for
all the numbers, not just the largest one.
See “TRUNC Function” in SAS Functions and CALL Routines: Reference for more
information about this function.
Double-Precision versus Single-Precision Floating-Point Numbers
You might have data created by an external program that you want to read into a SAS
data set. If the data is in floating-point representation, you can use the RBw.d informat to
read in the data. However, there are exceptions. The RBw.d informat might truncate
double-precision floating-point numbers if the w value is less than the size of the double-
precision floating-point number (8 on all the operating systems discussed in this section).
Therefore, the
RB8. informat corresponds to a full 8-byte floating point. The RB4.
informat corresponds to an 8-byte floating point truncated to 4 bytes, exactly the same as
a LENGTH 4 in the DATA step.
An 8-byte floating point that is truncated to 4 bytes might not be the same as a float
point in a C program. In the C language, an 8-byte floating-point number is called a
double. In Fortran, it is a REAL*8. In IBM PL/I, it is a FLOAT BINARY(53). A 4-byte
floating-point number is called a float in the C language, REAL*4 in Fortran, and
FLOAT BINARY(21) in IBM PL/I.
On the IBM mainframes, a single-precision floating-point number is exactly the same as
a double-precision number truncated to 4 bytes. On operating systems that use the IEEE
standard, this is not the case; a single-precision floating-point number uses a different
number of bits for its exponent and uses a different bias, so that reading in values using
the RB4. informat does not produce the expected results.
80 Chapter 4 • SAS Variables