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

时间:2013-10-30 07:56:37

标签: sas

我有一个数据集,我在其中存储了IN子句中使用的所有值。

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

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

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

这可以以任何方式完成吗?

2 个答案:

答案 0 :(得分:1)

您可以使用宏变量。

/* 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;

答案 1 :(得分:0)

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

proc sql ;
  create table output as
  select *
  from input 
  where a in(select distinct inval from invalues) ;
quit ;
相关问题