BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
Two datasets A and B have Id's.How to find the id's that are NOT matching between them.

I could use a merge:
if A and NOT B then Output A1;
if NOT A and B then output B1;

Then combine A1 and B1 and get distinct ids.
Is there any other way?
5 REPLIES 5
ieva
Pyrite | Level 9
You can also simply combile both of thes IF statements in one, so no need to merge afterwards:

if (a and not b) or ( b and not a);
SASPhile
Quartz | Level 8
Thanks Ieva
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SASPhile,

You can use even more simple logic: if NOT (a and b); like this:
[pre]
data a;
x=1; output;
x=2; output;
run;
data b;
x=3; output;
x=2; output;
run;
proc sort data=a;
by x;
run;
proc sort data=b;
by x;
run;
data dif;
merge a (in=a) b(in=b);
if not (a and b);
by x;
run;
[/pre]
Sincerely,
SPR
SASPhile
Quartz | Level 8
Thanks SPR!
Ksharp
Super User
Yes.
There is another way.Try to use proc sql + except .


[pre]
data temp;
set sashelp.class;
where sex eq 'F';
run;
proc sql;
select *
from sashelp.class as a
where a.sex not in (
select b.sex
from temp as b
) ;quit;
[/pre]


But it is low efficient for the sub-query.


Ksharp Message was edited by: Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1067 views
  • 0 likes
  • 4 in conversation