2017-10-17 73 views
2

此代码给出错误“期望整数常量”。为什么?这很简单,我找不到任何说in()不能用小数的东西。我需要在某个地方“做”吗?谢谢。IN函数不能使用小数点

data clustered; 
    set combd; 

if (avpm in(393821:450041) or avpm in(337601:393821) or avpm in  
    (225161:281381)) and fsp in (.8768:1) then class='1'; 

if (avpm in(112720:168940) or avpm in(56500:112720) or avpm in 
    (280.06:56500)) and fsp in (.8768:1) then class='2'; 

if avpm in(280.06:56500) and (fsp in (.507:.6303) or fsp in (.3838:.507) 
    or fsp in (.2606:.3838)) then class='3'; 

if avpm in(280.06:56500) and (fsp in (.1373:.2606) or fsp in 
    (.0141:.1373)) then class='4'; 

if avpm in(280.06:56500) and fsp in (.8768:1) then class='5'; 

if avpm in(280.06:56500) and (fsp in (.8768:1) or fsp in (.7535:.8768) or 
    fsp in (.6303:.7535)) then class='6'; 

run; 

回答

1

IN不带有小数工作。

事实上,IN可能不会做你认为它的作用。

IN()是一个操作符,做以下,根据SAS documentation on operators

等于1的列表的

list注意。也就是说,并不是说数字在开始和结束之间;相反,它将开始和结束作为整数列表进行扩展并评估它是否在该列表中。您可以在The IN operator in numeric comparisons的下一页看到:

您可以使用简写符号来指定要搜索的顺序整数范围。通过使用语法M:N作为要搜索的列表中的值来指定范围,其中M是下限,N是上限。 M和N必须是整数,并且M,N和M和N之间的所有整数都包含在范围内。

重要的是,任何数量的不是一个整数是由不包括在此范围定义。所以:

3.5 in (2:4) 

是错误的,因为3.5不在列表中(2,3,4)

data test; 
    x = 3.5; 
    y = x in (2:4); 
    put x= y=; 
    stop; 
run; 

x=3.5 y=0 

您需要使用ge和/或le(或gt和/或lt)做你想要什么。

0.8768 le fsp le 1 

您可以将它们链接在一起,因此它仍然相对容易编写。

+0

谢谢乔;说得通。 – mbs23

+0

in运算符使用十进制数字列表,如果它们是离散指定的,例如'如果x等于0.5,如果x in(0,0.5,1)'将为真。尽管如此,你无法真正期望SAS与无数的无限数字相匹配。 – david25272