BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jcis7
Pyrite | Level 9

Hello!

 

I have two sas tables and am trying figure out which observations between the two tables are different.

I don't know if table a has observations table b doesn't have and vice versa.

 

How would I do that?  They differ by the identifying variable schcode

 

proc sql;

create table differing as

select a.*

from a

left join b on a.schcode=b.schcode;

quit;

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
nehalsanghvi
Pyrite | Level 9

Are you simply trying to see which observations are in one and and not in the other? If so, then this would work:

 

proc sql;
create table differing as
select *, 'In A, not in B' as Note
from a
where schcode not in (select schcode from b)
union
select *, 'In B, not in A' as Note
from b
where schcode not in (select schcode from a);
quit;

 

If you're trying to column compare values as well, then proc compare is the way to go.

View solution in original post

3 REPLIES 3
jhlaramore
SAS Employee

Take a look at PROC COMPARE. It's an excellent option for comparing observations between two SAS data sets. 

 

http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1nwxbchh5hpu1n1h28km...

 

 

nehalsanghvi
Pyrite | Level 9

Are you simply trying to see which observations are in one and and not in the other? If so, then this would work:

 

proc sql;
create table differing as
select *, 'In A, not in B' as Note
from a
where schcode not in (select schcode from b)
union
select *, 'In B, not in A' as Note
from b
where schcode not in (select schcode from a);
quit;

 

If you're trying to column compare values as well, then proc compare is the way to go.

jcis7
Pyrite | Level 9

Thank you everyone :)!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 797 views
  • 1 like
  • 3 in conversation