How can I use Proc SQL to search for all records that exist in only one table and not in the other?

I am trying to do this in the Enterprise Guide with a task, otherwise I would just use the data step.

In the data step it will be:

data names;
 input name $;
 datalines;
  John
  Mary
  Sally
  Fred
  Paul
 ;
run;

data check;
 input name $;
 datalines;
  Mary
  Fred
 ;

Proc sort data=names; by name; run;
Proc sort data=check; by name; run;

Data work.not_in_check;
 merge names(in=n) check(in=c);
 by name;
 if n and not c;
run;
+5
source share
4 answers

Here is one way. There are, of course, many others.

proc sql;
 create table not_in_check as
 select name
 from names
 where name not in (select name from check);
quit;
+9
source

Another small change:

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;
+7
source

- , .

, sex = M, = F.

:

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;

, 100 . . .

P.S: , , . , , .:)

My first answer. :)

+1
source
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
source

All Articles