Furthermore, although computers do allow the use of decimal numbers and decimal
arithmetic via human-centric software interfaces, all numbers and data are eventually
converted to binary format to be stored and processed by the computer internally. It is in
the conversion between these 2 number systems – decimal to binary – that precision is
affected and rounding errors are introduced.
Truncation in Binary Numbers
Just like there are decimal values with infinitely repeating representations, there are also
binary values that have infinitely repeating representations. However, the numbers that
are imprecise in decimal are not always the same ones that are imprecise in binary.
For example, the decimal value 1/10 has a finite decimal representation (0.1), but in
binary it has an infinitely repeating representation. In binary, the value converts to
where the pattern 0011 is repeated indefinitely. As a result, the value will be rounded
when stored on a computer.
Performing calculations and comparisons on imprecise numbers in SAS can lead to
unexpected results. Even the simplest calculations can lead to a wrong conclusion.
Hardware cannot always match what might seem obvious and expected in the decimal
For example, in decimal arithmetic, the expression (3 x 0.1) is expected to be equal
0.3, so the difference between (3 x 0.1) and (0.3), must be 0. Because the
decimal values 0.1 and 0.3 do not have exact binary representations, this equality does
not hold true in binary arithmetic. If you compute the difference between the two values
in a SAS program, the result is not 0, as Example Code 4.6 on page 61 illustrates.
In the example, SAS sets the variables point_three and
three_times_point_three to 0.3 and (3 x 0.1), respectively. It then compares
the two values by subtracting one from the other and writing the result to the SAS log:
Example Code 4.6 Comparing Imprecise Values in SAS
three_times_point_one= 3 * 0.1;
difference= point_three - three_times_point_one;
put 'The difference is ' difference;
Output 4.5 Log Output for Comparing Imprecise Values in SAS
The log output shows that (3 x 0.1) — 0.3 does not equal 0, as it does in decimal
arithmetic. This is because the variable "difference" is the result of calculations that are
performed on rounded values, or, infinitely repeating binary values.
Numerical Accuracy in SAS Software 61