【问题标题】:SAS DATA STEP WHERE CONDITION IN A LISTSAS 数据步骤列表中的条件
【发布时间】:2022-11-19 01:56:24
【问题描述】:

我试图通过使用 SAS 中的数据步骤来过滤列表中的数据

proc sql;
create table id_list as
select distinct id from customer;
quit;

data test;
set fulldata;
where id in id_list;
run;

它不起作用。但是,如果我使用“where id in (1,2,3)”,它会起作用。 任何人都可以帮助我了解数据列表中的位置吗? 谢谢

【问题讨论】:

    标签: sql sas where-clause datastep


    【解决方案1】:

    您需要使用宏变量来保存和引用您的 ID 列表。您不能在数据步骤中的 where 语句中引用单独的表。

    proc sql noprint;
        select distinct id 
        into :id_list separated by ','
        from customer
    quit;
    

    如果您的不同客户 ID 是 123,则 &id_list 将解析为 1,2,3

    data test;
        set fulldata;
        where id in(&id_list);
    run;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      相关资源
      最近更新 更多