Formatted Input - a small example

From sasCommunity

Jump to: navigation, search

The following program creates a data set using formatted input. It demonstrates various issues that can come up when reading numeric values while using formats.

data silly;
input @1 w 4.
@6 x 4.0
@11 y 4.1
@17 z 4.2;
put w= x= y= z=;
datalines;
3.1 12.3 123.4 1234.5
31 123 1234 12345
run;

The LOG shows that not all of the values have been read as anticipated.

7    datalines;
w=3.1 x=12.3 y=123 z=12.34
w=31 x=123 y=123.4 z=12.34
NOTE: The data set WORK.SILLY has 2 observations and 4 variables.

W and X These informats do not specify any decimal places consequently none are implied.
Y One implied decimal place is specified. Since the width (4) is insufficient to read the entire number 123.4 (a width of 5 would be needed) information is lost.
Z For both data lines the width is insufficient to read the entire number. Worse for the first data line, the decimal point is not read and the number 1234.5 is read as 12.34.


Remember to watch both the width of the format and the number of decimal points that you want to read. It makes a difference!

Personal tools