Contributor
Posts: 74

# understanding informat

can somebody help me understand how this informat works:

data a;
input d1 \$;
cards;
700.1
723.45
166.3
902
991
217.01
98
511
105.45
;
run;

data b;
set a;
format d2 8.2;
d2=input(d1, 8.2);
run;
proc print;
run;

I though I would have values in d2 as numeric form of d1 with 2 digit places. but what I got was this:

Obs d1 d2

1 700.1 700.10
2 723.45 723.45
3 166.3 166.30
4 902 9.02
5 991 9.91
6 217.01 217.01
7 98 0.98
8 511 5.11
9 105.45 105.45

if values in d1 represents an integer (no digit) d2 will add 2 digit places. so 98 becomes 0.98 and 511 becomes 5.11.

I can work around this situation by adding a dot to d1, but can somebody help me understand what happened?
Super Contributor
Posts: 3,176

## Re: understanding informat

Posted in reply to abdullala
The SAS numeric variable you assigned is associated with a FORMAT, as you coded, so the PROC PRINT is using that format which is different than what SAS has stored internally. Either remove the SAS FORMAT statement or use another (more revealing) output format such as BEST. in your code.

The SAS DOC has topic discussion about SAS numeric variable precision and storage.

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 74

## Re: understanding informat

nah -- didn't work. it only works if I change the informat from '8.2' to 'best.'. I want to know why informat 8.2 does not work. this is not about precision, this is about how informat works. thanks!
Super Contributor
Posts: 359

## Re: understanding informat

Posted in reply to abdullala
The problem seems to be with your input(d1, 8.2) statement. You are telling SAS to read 2 decimal places. Use a best. here and SAS will respect your decimal placement.

so d2 = input(d1, best.);

w.d
Syntax Description

w
specifies the width of the input field.

Range: 1-32

d
optionally specifies the power of 10 by which to divide the value. If the data contain decimal points, the d value is ignored.

Range: 0-31
Contributor
Posts: 74

## Re: understanding informat

thank you very much Flip! that's what I have been missing.
Valued Guide
Posts: 2,191

## Re: understanding informat

Posted in reply to abdullala
when your text contains the decimal point never tell a numeric informat how many decimals are present. That feature is needed only where the text has no decimal point.
Use informat 8. or percent8.
Discussion stats
• 5 replies
• 131 views
• 0 likes
• 4 in conversation