使用SAS中的另一个数据集过滤数据集

时间:2015-12-02 23:43:02

标签: sas

我有以下两个数据集。如何在DATA1

中的DATA2中排除这些观察结果
data DATA1;
   input Name $ 1-25;
   datalines;
Vincent, Martina   
Phillipon, Marie-Odile    
Gunter, Thomas            
Harbinger, Nicholas       
Benito, Gisela            
Rudelich, Herbert         
Sirignano, Emily          
Morrison, Michael         
;
run;

data DATA2;
   input Name $ 1-25;
   datalines;
Vincent, Martina   
Morrison, Michael         
;
run;

1 个答案:

答案 0 :(得分:2)

经典示例,经常辩论(最有效)this的SQL查询。

考虑proc sql等效解决方案:

proc sql;
    create table Data3 as 
         select Data1.Name 
           from Data1 
      left join Data2 on Data1.Name = Data2.Name
          where Data2.Name is null;
quit;

proc sql;
    create table Data4 as 
         select Data1.Name 
           from Data1 
          where Data1.Name 
         not in (select Data2.Name from Data2);
quit;

proc sql;
    create table Data5 as 
         select Data1.Name 
           from Data1 
          where not exists 
         (select Data2.Name from Data2
          where Data1.Name = Data2.Name);
quit;

<强>输出

Name 
Phillipon, Marie-Odile 
Gunter, Thomas 
Harbinger, Nicholas 
Benito, Gisela 
Rudelich, Herbert 
Sirignano, Emily