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
Transferring Data between Operating Systems
Problems of precision and magnitude can occur when you transfer data containing very
large or very small numeric values that are represented in floating-point notation. Table
4.9 on page 64 shows the maximum number of digits of the base, exponent, and
mantissa. Because there are differences in the maximum values that can be stored in
different operating environments, there might be problems in transferring your floating-
point data from one computer to another.
Consider transporting data between an IBM mainframe and a PC, for example. The IBM
mainframe has a range limit of approximately .54E−78 to .72E76 (and their negative
equivalents and 0) for its floating-point numbers.
Other computers, such as the PC, have wider limits (the PC has an upper limit of
approximately 1E308). Therefore, if you are transferring numbers in the magnitude of
1E100 from a PC to a mainframe, you lose that magnitude. During data transfer, the
number is set to the minimum or maximum allowable on that operating system, so
1E100 on a PC is converted to a value that is approximately .72E76 on an IBM
mainframe.
CAUTION:
Transfer of data between computers can affect numerical precision.
If you are transferring data from an IBM mainframe to a PC, notice that the number of
bits for the mantissa is 4 less than that for an IBM mainframe. This means that you lose
4 bits when moving to a PC.
This precision and magnitude difference is a factor when moving from one operating
environment to any other where the floating-point representation is different.
An alternative solution, and probably the safest way to avoid numerical precision
problems when transferring data between operating systems, is to convert the numbers in
your data to integers.
For more information about moving data between operating systems, see Moving and
Accessing SAS Files.
Numerical Accuracy in SAS Software 81
82 Chapter 4 SAS Variables
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.73.127