How can I use Proc SQL to find all the records that only exist in one table but not the other?

前端 未结 4 494
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 14:33

I\'m trying to do this in Enterprise Guide, with a task, otherwise I would just use a data step.

In a data step, this would be:

data names;
 input name $         


        
相关标签:
4条回答
  • 2021-02-06 14:53

    Here's one way. There are surely many others.

    proc sql;
     create table not_in_check as
     select name
     from names
     where name not in (select name from check);
    quit;
    
    0 讨论(0)
  • 2021-02-06 14:55

    The following method is pretty simple way to get records present in one table and not in the other.

    Created table new with records containing sex = M, the result after the query will be records with sex = F.

    Example:

    data new;
    set sashelp.class;
    where sex = 'M';
    run;
    proc sql;
    create table new1 as
    select * from sashelp.class
    except all 
    select * from new;
    quit;
    

    Will put the code to test on my actual datasets which are of around 100k obs and update the result.

    P.S: I know the question has been asked answered and forgotten,I was looking for a way to do the above and couldn't find a direct answer any where. So, adding so that it may come handy. :)

    My first answer also. :)

    0 讨论(0)
  • 2021-02-06 14:58

    Another slight variation is:

    proc sql;
    create table not_in_check as select 
     a.* from names as a left join 
              check as b on
              a.name=b.name
              where b.name is null;
    quit;
    
    0 讨论(0)
  • 2021-02-06 15:02
    proc sql;
     create table inNamesNotIncheck
     as
     select *
     from names n
     where not exists
     (select name
     from check c
     where n.name=c.name);
    quit;
    
    0 讨论(0)
提交回复
热议问题