You already had some good suggestions on how to solve this - the problem you are encountering is the following:
Numbers in SAS are internally represented as base 2 floating points (unless you are on the mainframe, then they are base 16 floating points). This means that some decimal numbers can be represented exactly, for instance your MIU values:
do miu=2 to 3.5 by 0.5;
- here you will have 2E0, 5E-1, 3E0 etc. up to 7E-1, as the numbers are all possible to calculate as integers, some of them divided by 2.
But your thetas are not like that - the number 0.2 cannot be represented exactly as an integer divided by a power of 2. So when you keep adding 0.2 to a decimal number, the result will eventually become inexact. In the case you show, this happens at 1.6.
One other possibility, apart from rounding or using integers instead of decimals is to spell out the numbers you want in a list:
do theta=0.8,1.0,1.2...2.8;
which will give the "exact" decimal numbers. One way to do it is like this - put the list of values you want in a macro variable:
data _null_;
length thetas $200;
do theta=0.8 to 2.8 by 0.2;
call catx(',',thetas,put(theta,3.1));
end;
call symputx('thetas',thetas);
run;
data chk;
do miu=2 to 3.5 by 0.5;
do sd=0.7 to 1.3 by 0.3;
do theta=&thetas;
do n=6 to 30 by 4;
output;
end;
end;
end;
end;
run;
- of course, you may want to do the same for the SD values:
data _null_;
length thetas $200;
do theta=0.8 to 2.8 by 0.2;
call catx(',',thetas,put(theta,3.1));
end;
call symputx('thetas',thetas);
length sds $200;
do sd=0.7 to 1.3 by 0.3;
call catx(',',sds,put(sd,3.1));
end;
call symputx('sds',sds);
run;
data chk;
do miu=2 to 3.5 by 0.5;
do sd=&sds;
do theta=&thetas;
do n=6 to 30 by 4;
output;
end;
end;
end;
end;
run;
Is this worth the trouble? Maybe, if you are doing a lot of comparisons on the same data - then it probably will be faster than rounding every time you try to look up a value. And if you have a lot of inexperienced users trying to find the different values, this solution may save a lot of time - not just CPU time, but actual working hours, which are a lot more expensive.
... View more