RBw.d Informat: UNIX

Reads numeric data that is stored in real binary (floating-point) notation.
Category: Numeric
Default: 4
Ranges: 2 to 8, 0 to 10
UNIX specifics: floating-point representation; supports single-precision numbers only for those applications that truncate numeric data
See: RBw.d Informat in SAS Formats and Informats: Reference

Details

The RBw.d informat reads numeric data that is stored in real binary (floating-point) notation. SAS stores all numeric values in floating-point.
It is usually impossible to type 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 SAS because the RBw.d informat is designed to read only double-precision data.
All UNIX systems that are currently supported by SAS 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 programs that are written in the C and Fortran languages can produce only single-precision 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 that 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 the following 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);
fclose(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.);
  run;
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.