2012-07-03 41 views
1

Sas是否提供了chain-表達式的機制?SAS:IF語句中的表達式

確實Sas提供In的機制 - 條款?

簡單的例子:

a = '09MAY2010'd; 
    b = '17MAY2010'd; 

if (a<=c<=b) then do; /*code*/ end; 
if (c in (a:b)) then do; /*code*/ end; 

也許,如果/,語句什麼好的技巧?
您的建議和建議,請。
謝謝!

+0

謝謝!我已經清除了我的錯誤知識 – gaussblurinc

+1

如果你知道了,你應該發佈並回答你的問題。 – Banjer

回答

2

你的榜樣,改了一下:

data _null_; 
    a = '09MAY2010'd; 
    b = '17MAY2010'd; 
    c = '17MAY2010'd; 

    if (a<=c<=b) then do; 
     putlog "a<=c<=b"; 
    end; 

    select (c); 
     when (a, b) putlog "in a, b"; 
     when ('17MAY2010'd) putlog "'17MAY2010'd";/* not used, only first match is executed */ 
     otherwise; 
    end; 

run; 

與IF或使用運營商WHERE子句需要在列表中的常量。

+0

不錯,但第二個呢? ('c in(a:b)')我是對的嗎,我不能使用帶有範圍的IF語句,只有IF的每個邊界是常量? – gaussblurinc

+0

不確定你的意思:if(a <= c <= b)有效地引用由變量定義的範圍,而不是常量。 – vasja

+0

no-no,我的意思是'(c in(a:b))'作爲一個範圍。鏈比較工作。 – gaussblurinc

0

除了IN運營商,只接受paranthesis內是恆定值,也有一個(無證)IN功能,這可以通過使用變量可以使用,所以不是if c in(a,b)可以使用if in(c,a,b)這也將工作當和b是變量。

另一種可能性是使用WHICHNWHICHC功能,其具有相同的語法,並且其返回0FALSE)當未找到匹配,否則(第一)匹配的數目。