This minimal working example is supposed to generate "temp" with "x" from 0.1 to 0.9 by 0.1, and separates it observation by observation from "temp1" to "temp9," but SAS works well with x∈{1,2,4,5,6,7}, while it doesn't with x∈{3,8,9}. I cannot even guess what's wrong with this code since it's too simple.
data temp;
do x=0.1 to 0.9 by 0.1;
output;
end;
run;
%macro separate;
%do x=1 %to 9;
/*--------------------------------------------------
This only works with x in 1, 2, 4, 5, 6 and 7.
--------------------------------------------------*/
data temp&x.;
set temp;
where x=0.&x.;
run;
%end;
%mend;
%separate;
quit;
Thanks in advance. By the way, I tried if instead of where, but the result was same.
Run this:
data t;
set temp;
A=X-round(X,0.1);
format A 32.16;
run;
X A
0.1 0.0000000000000000
0.2 0.0000000000000000
0.3 0.0000000000000001
0.4 0.0000000000000000
0.5 0.0000000000000000
0.6 0.0000000000000000
0.7 0.0000000000000000
0.8 -0.0000000000000001
0.9 -0.0000000000000001
and read about numeric precision in SAS (and elsewhere).
All has been said already. Time to learn how computers work. 🙂
Run this:
data t;
set temp;
A=X-round(X,0.1);
format A 32.16;
run;
X A
0.1 0.0000000000000000
0.2 0.0000000000000000
0.3 0.0000000000000001
0.4 0.0000000000000000
0.5 0.0000000000000000
0.6 0.0000000000000000
0.7 0.0000000000000000
0.8 -0.0000000000000001
0.9 -0.0000000000000001
and read about numeric precision in SAS (and elsewhere).
All has been said already. Time to learn how computers work. 🙂
Thank you, Chris. I modified the original code.
data temp;
do x=0.1 to 0.9 by 0.1;
output;
end;
run;
%macro separate;
%do x=1 %to 9;
data temp&x.;
set temp;
where round(x,0.1)=0.&x.;
run;
%end;
%mend;
%separate;
quit;
With no reason I thought that there is no numerical concern in SAS as it displays 0.3 rather than 0.3000000000000001. I'd better be more careful if it's a float type.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.