SAS 数值比较的奇怪行为;精度问题? [英] Odd behavior with SAS numeric comparison; precision issue?

查看:27
本文介绍了SAS 数值比较的奇怪行为;精度问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SAS 中运行一个简单的不等式过滤器,如下所示:

I'm running a simple inequality filter in SAS as follows:

data my_data;
    set my_data;
    my_var = sum(parent_var1, -parent_var2)
run;

proc sql;
    select my_var format=32.32
    from my_data
    where my_var < 0.02;
quit;

我得到以下结果:

my_var
.0200000000000000000000000000000
.0200000000000000000000000000000
.0200000000000000000000000000000
(etc...)

如果不是很明显,问题是我想要数字低于 .02,但它看起来很像我的数字 .02.

The problem, in case it's not obvious, is that I want numbers below .02, but it looks very much like my number is .02.

根据我查看数据集时列出的属性,my_var 的长度设置为 8.parent_var1parent_var2 都是十进制数字,长度为 8,格式为 8.5.

According to the properties listed when I view my dataset, the length of my_var is set to 8. parent_var1 and parent_var2 are both decimal numbers, length 8 and format 8.5.

有人能解释一下这里可能发生了什么吗?是否有一些我看不到的隐藏精度?

Can someone explain what might be going on here? Is there some hidden precision somewhere that I'm not able to see?

推荐答案

SAS只有浮点二进制数据类型.没有任何类型可以代替进行十进制算术.因此,您的值可能略小于 0.02.

SAS only has floating point binary data type for numbers. There is no type that does decimal arithmetic instead. So you might have a value that is slightly less than 0.02.

您可能希望将值四舍五入到某个固定的小数位数,例如四位或五位.在您的数据上尝试此代码并检查您是否仍然看到那些 0.02 值.

You might want to round your values to some fixed number of decimal places, say four or five. Try this code on your data and check if you still see those 0.02 value.

data my_data;
   set my_data;
   my_var = round(sum(parent_var1, -parent_var2),0.00001) ;
   if my_var < 0.02 then put (my_var paren_var1 parent_var2) (= best32.8) ;
run;

这篇关于SAS 数值比较的奇怪行为;精度问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆