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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.