Chapter Contents

Previous

Next
SAS Companion for the CMS Environment

Representation of Numeric Variables

The way in which numbers are represented in your SAS programs affects both the magnitude and the precision of your numeric calculations. The factors that affect your calculations are discussed in detail in SAS Language Reference: Concepts. When you run SAS under the CMS environment, the most important factor you should be aware of is the way in which floating-point numbers and integers are stored.


Representation of Floating-Point Numbers

All numeric values are stored in SAS data sets and are maintained internally in floating-point (real binary) representation. Floating-point representation is an implementation of what is generally known as scientific notation. That is, values are represented as numbers between 0 and 1 times a power of 10. For example, 1234 is .1234 times 10 to the fourth power, which is the same as the following expression:

[IMAGE]

Under CMS, floating-point representation (unlike scientific notation) uses a base of 16 rather than base 10. IBM mainframe systems all use the same floating-point representation, which is made up of 4, 8, or 16 bytes. SAS always uses 8 bytes, as follows:

SEEEEEEE MMMMMMMM MMMMMMMM MMMMMMMM
byte 1   byte 2   byte 3   byte 4
MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM
byte 5   byte 6   byte 7   byte 8

This representation corresponds to bytes of data, with each character occupying 1 bit. The S in byte 1 is the sign bit of the number. If the sign bit is zero, the number is positive. Conversely, if the sign bit is one, the number is negative. The seven E characters in byte 1 represent a binary integer that is known as the characteristic. The characteristic represents a signed exponent and is obtained by adding the bias to the actual exponent. The bias is defined as an offset that is used to allow for both negative and positive exponents, with the bias representing 0. If a bias was not used, an additional sign bit for the exponent would have to be allocated. For example, IBM mainframes employ a bias of 40 (base 16). A characteristic with the value 42 represents an exponent of +2, whereas a characteristic of 3D represents an exponent of -3.

The remaining M characters in bytes 2 through 8 represent the bits of the mantissa. There is an implied radix point before the most significant bit of the mantissa, which also implies that the mantissa is always strictly less than 1. The term radix point is used instead of decimal point, because decimal point implies that we are working with decimal (base 10) numbers, which is not the case.

The exponent has a base associated with it. Do not confuse this with the base in which the exponent is represented. The exponent is always represented in binary, but the exponent is used to determine what power of the exponent's base should be multiplied by the mantissa. In the case of the IBM mainframes, the exponent's base is 16.

Each bit in the mantissa represents a fraction whose numerator is 1 and whose denominator is a power of 2. For example, the most significant bit in byte 2 represents 1/2 ** 1, the next most significant bit represents 1/2 ** 2, and so on. In other words, the mantissa is the sum of a series of fractions such as 1/2, 1/4, 1/8, and so on. Therefore, in order for any floating-point number to be represented exactly, you must be able to express it as the previously mentioned sum. For example, 100 is represented as the following expression:

(1/4 + 1/8 + 1/64) * (16 ** 2)

The following two examples illustrate how the preceding expression is obtained. The first example is in base 10. In decimal notation, the value 100 is represented as follows:

100.

The period in this number is the radix point. The mantissa must be less than 1; therefore, you normalize this value by shifting the number three places to the right, which produces the following value:

.100

Because the number was shifted three places to the right, 3 is the exponent, which results in the following expression:

.100*10**3=100

The second example is in base 16. In hexadecimal notation, 100 (base 10) is written as follows:

64.

The period in this number is the radix point. Shifting the number two places to the left produces the following value:

.64

Shifting the number two places also indicates an exponent of 2. Rewriting the number in binary produces the following value:

.01100100

Finally, the value .01100100 can be represented in the following expression:

[IMAGE]

In this example, the exponent is 2. To represent theexponent, you add the bias of 64 to the exponent. The hexadecimal representation of the resulting value, 66, is 42. The binary representation is as follows:

01000010 01100100 00000000 00000000
00000000 00000000 00000000 00000000

Floating-point numbers that have negative exponents are represented with characteristics that are less than '40'x. When you subtract '40'x from a number that is less than '40'x, the difference is a negative value that represents the exponent. An example of such a number is the floating-point representation of .0312510, which is

'3F80000000000000'x

Subtracting '40'x from the characteristic, '3F'x, gives an exponent of - 116. This exponent is applied to the 14-digit fraction, '80000000000000'x, giving a value of .0816, which is equal to .0312510.


Representation of Integers

As with other numeric values, SAS maintains integer variables in floating-point (real binary) representation. But under CMS, numeric integer values are typically represented as binary (fixed-point) values by using two's complement representation. SAS can read and write these values by using informats and formats, but it does not process them internally in this form.

You can use the IBw.d informat and format to read and write these binary values. Each integer uses 4 bytes (32 bits) of storage space; thus, the range of values that can be represented is -2,147,483,648 to 2,147,483,647.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.