Chapter Contents


RBw.d informat

RBw.d informat

Reads real binary (floating-point) data

Width range: 2 to 8
Default width: 4
Decimal range: 0 to 10
UNIX specifics: floating-point representation; supports single-precision numbers only for those applications that truncate numeric data



The RBw.d informat reads numeric data that are stored in real binary (floating-point) notation. The SAS System stores all numeric values in floating-point.

It is usually impossible to type in floating-point binary data directly from a console, but many programs write floating-point binary data. Use caution if you are using the RBw.d informat to read floating-point data created by programs other than the SAS System because the RBw.d informat is designed to read only double-precision data.

All UNIX systems that are currently supported by the SAS System use the IEEE standard for floating-point representation. This representation supports both single-precision and double-precision floating-point numbers. Double-precision representation has more bytes of precision, and the data within the representation is interpreted differently. For example, for single-precision, the value of 1 in hexadecimal representation is 3F800000. For double-precision, the hexadecimal representation of 1 is 3FF0000000000000.

The RBw.d informat is designed to read only double-precision data. It supports widths less than 8 only for applications that truncate numeric data for space-saving purposes. RB4. does not expect a single-precision floating-point number; it expects a double-precision number truncated to four bytes. Using the example of 1 above, RB4. expects 3FF00000 to be the hexadecimal representation of the four bytes of data to be interpreted as 1. If given 3F800000, the single-precision value of 1, a different number results.

External programs such as those written in C and FORTRAN can only produce single- or double-precision floating-point numbers. No length other than four or eight bytes is allowed. RBw.d allows a length of 3 through 8, depending on the storage you need to save.

The FLOAT4. informat has been created to read a single-precision floating-point number. If you read 3F800000 with FLOAT4., the result is a value of 1.

To read data created by a C or FORTRAN program, you need to decide on the proper informat to use. If the floating-point numbers require an eight-byte width, you should use the RB8. informat. If the floating point numbers require a four-byte width, you should use FLOAT4.

Consider this C example:

#include <stdio.h>

main() {

FILE *fp;
float x[3];

fp = fopen("test.dat","wb");
x[0] = 1; x[1] = 2; x[2] = 3;

fwrite((char *)x,sizeof(float),3,fp);
The file test.dat contains 3f8000004000000040400000 in hexadecimal representation.

The following statements read test.dat correctly:

  data _null_;
     infile 'test.dat';
     input (x y z) (float4.);

Also available is the IEEEw.d informat, which reads IEEE floating-point data. On UNIX systems, IEEE8. is equivalent to RB8., and IEEE4. is equivalent to FLOAT4. IEEEw.d can be used on any platform, as long as the original IEEE binary data originated on a platform that uses the IEEE representation.

For more details, see Reading and Writing Binary Data .

Chapter Contents



Top of Page

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