解读SAS中的双重不等式

时间:2013-08-30 15:04:34

标签: math sas logical-operators

我写了

  

while while(A< = B< = C); ...; end

并且我没有得到我期望的结果( A< = B和B< = C )。那么SAS如何解释表达式A< = B< = C?注意:SAS没有给出A< = B< = C。

的错误

2 个答案:

答案 0 :(得分:3)

我相信它从左到右评估:

(A <= B) <= C

A <= B评估为01。然后将此值与C进行比较。

答案 1 :(得分:2)

这可以按照您在数据步骤中的预期工作。它在PROC IML中不起作用。

1189  data _null_;
1190  a = 10;
1191  b = 10;
1192  c = 15;
1193
1194  do while(a<=b<=c);
1195      put b=;
1196      b = b + 1;
1197      /*Abort if this runs away*/
1198      if b > 20 then
1199          stop;
1200  end;
1201  run;

b=10
b=11
b=12
b=13
b=14
b=15
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

1203  proc iml;
NOTE: IML Ready
1204  a = 10;
1205  b = 10;
1206  c = 15;
1207  file log;
1208
1209  do while (a<=b<=c);
1210      put "B=" b;
1211      b = b+1;
1212
1213      if b>20 then stop;
1214  end;
B=       10
B=       11
B=       12
B=       13
B=       14
B=       15
B=       16
B=       17
B=       18
B=       19
B=       20
1215  quit;
NOTE: Exiting IML.
NOTE: PROCEDURE IML used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds

IML与Base SAS的逻辑语法略有不同。在IML中,使用

do while ( (a<=b) & (b<=c));