在 SAS 中使用数据集变量值作为 IN 子句值



我有一个数据集,我将要在 IN 子句中使用的所有值存储在其他地方。

DATA INVALUES;
INPUT INVAL;
DATALINES;
1
2
3
;
RUN;

我必须在另一个数据集中使用值,如下所示。

DATA OUTPUT;
SET INPUT;
IF A IN ( --- INVAL  values from dataset INVALUES ----);
;
RUN;

这能以任何方式完成吗?

您可以为此使用宏变量。

/* Put the inval values in a comma separated macro variable  */
proc sql;
select inval into:inval separated by ","
from invalues;
/* prints the macro variable in the log */
%put &inval; /* 1,2,3 */
/* use the macrovariable in the IF statement */
DATA OUTPUT;
SET INPUT;
IF A IN &inval;
RUN;

一个更简洁的方法是在SQL中使用子查询,无需担心数据类型/引用。

处理器 SQL ;  将表输出创建为  选择*  从输入  其中 in(从 invalues 中选择不同的 inval);退出;

最新更新