在SAS DATA步骤中使用WHERE SAME AND运算符

时间:2018-11-30 20:13:16

标签: sas

我是SAS语言学习的初学者。我了解到,我们在SAS中使用了五个Special_where运算符。其中之一是WHERE SAME AND运算符。谁能帮我一个例子如何使用该运算符

预先感谢

1 个答案:

答案 0 :(得分:3)

您可以在DATA步骤中使用WHERE语句,在PROC步骤中也可能更有用。 WHERE SAME AND的另一个名字WHERE ALSO也许也更容易记住,它使您可以使用多个语句来添加更多限制。

这很容易通过以下示例看到:

proc means data=sashelp.class ;
  where sex='M';
  where also age > 12 ;
  var height;
run;

因为SAS会将​​产生的子设置条件回显到LOG。

1334  proc means data=sashelp.class ;
1335    where sex='M';
1336    where also age > 12 ;
NOTE: WHERE clause has been augmented.
1337    var height;
1338  run;

NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 6 observations read from the data set SASHELP.CLASS.
      WHERE (sex='M') and (age>12);

请注意,您同时使用WHEREWHERE ALSO语句,顺序会有所不同。

1339  proc means data=sashelp.class ;
1340    where also age > 12 ;
NOTE: WHERE clause has been augmented.
1341    where sex='M';
NOTE: WHERE clause has been replaced.
1342    var height;
1343  run;

NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 10 observations read from the data set SASHELP.CLASS.
      WHERE sex='M';

但是您始终可以对所有语句使用WHERE ALSO,然后顺序就无所谓了。

1344  proc means data=sashelp.class ;
1345    where also age > 12 ;
NOTE: WHERE clause has been augmented.
1346    where also sex='M';
NOTE: WHERE clause has been augmented.
1347    var height;
1348  run;

NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 6 observations read from the data set SASHELP.CLASS.
      WHERE (age>12) and (sex='M');