Reputation: 4006
In a data step, if I do
strip(put(number,best32.))
I get a precision error for some numbers and not for others:
0.2804 --> "0.2804"
0.0804 --> "0.08039999999999"
I don't understand why the first number is perfectly transformed into a string and the second has a precision error. Is it because the real number is in fact 0.08039999999999 (8 bytes length) and that SAS doesn't show as much precision (in Enterprise Guide)?
I tried this instead
strip(put(number,20.10))
but then I get much unneeded zeros.
0.2804 --> "0.2804000000"
0.0804 --> "0.0804000000"
finally I found this to do what I need:
strip(cats(number))
Is this the best option?
Upvotes: 0
Views: 56
Reputation: 51566
It is because your actual number is closer to 0.08039999999999 than to 0.0804. So when you asked it to present the data using the best it can do in 32 characters it picked the former.
Try running this code.
data _null_ ;
input x ;
s = put(x,best32.);
put (x s) (=);
cards;
0.2804
0.0804
0.08039999999
;
Upvotes: 1