Hi everybody!
I'm not getting this:
I created a data set via a do-loop, data x, below.
When I use a w.d format on the value that I 'see' in the output data(value), the value is rounded up(fvalue).
When I create a hard value for 0.245 and use the same w.d format, the value is rounded down(fvalue2).
Clearly, SAS does not see the raw value of 0.245 coming from the data as 0.245.
Question is why?
Thanks for considering and I hope this is clear.
Jon
data x;
do i= .01 to .99 by .0001;
value = i;
output;
end;
run;
data y;
set x;
fvalue=value;
fvalue2=0.2450;
rawvalue=fvalue2;
format fvalue fvalue2 8.2;
drop i;
run;
when is 0.245 not 0.245?
Obs value fvalue rawvalue fvalue2
1 0.245 0.24 0.245 0.25
It's actually worse than you think.
Run this:
data x;
do X= .244 to .245 by .0001;
Y=round(X,0.0001);
output;
end;
format X Y 20.16;
run;
to obtain (on a PC):
X | Y |
---|---|
0.2440000000000000 | 0.2440000000000000 |
0.2441000000000000 | 0.2441000000000000 |
0.2442000000000000 | 0.2442000000000000 |
0.2443000000000000 | 0.2443000000000000 |
0.2444000000000000 | 0.2444000000000000 |
0.2444999999999900 | 0.2445000000000000 |
0.2445999999999900 | 0.2446000000000000 |
0.2446999999999900 | 0.2447000000000000 |
0.2447999999999900 | 0.2448000000000000 |
0.2448999999999900 | 0.2449000000000000 |
0.2449999999999900 | 0.2450000000000000 |
Read about numeric precision to know more.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.