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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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