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

data t1;
input id1 $3. id2 $5.;
cards;
123 hkg5
689 yukq
567 khnx
;
run;
data t2;
input id1 $3. id2 $5.;
cards;
123 hkg5
569 yukq
567 khnt
;
run;

 

I want to get mis-matched records from t1 and t2 where the id1 is different in two tables for id2 values, In the above example I just want to retrieve 567 khnt


what is the best way to compare two columns from two tables?

trying to replicate the following query that is working fine in other application..

select t1.custid,t2.custid,t2.id2,ord_date from t2 left join t1 using(id2)where t2.custid != t1.custid

 

 

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Stalk wrote:

...

I want to get mis-matched records from t1 and t2 where the id1 is different in two tables for id2 values, In the above example I just want to retrieve 567 khnt


Based on the sample data you've provided the only matching row over ID2 that has different values for ID1 is as below:

Patrick_0-1664925525306.png

proc sql;
  select 
    t1.id1,
    t2.id1,
    t2.id2
  from t2 inner join t1
    on t2.id2=t1.id2
  where t2.id1 ne t1.id1
  ;
quit;

What am I missing?

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

@Stalk wrote:

...

I want to get mis-matched records from t1 and t2 where the id1 is different in two tables for id2 values, In the above example I just want to retrieve 567 khnt


Based on the sample data you've provided the only matching row over ID2 that has different values for ID1 is as below:

Patrick_0-1664925525306.png

proc sql;
  select 
    t1.id1,
    t2.id1,
    t2.id2
  from t2 inner join t1
    on t2.id2=t1.id2
  where t2.id1 ne t1.id1
  ;
quit;

What am I missing?

Stalk
Pyrite | Level 9
Patrick, you are right. Your query's results is exactly what I am looking for.
My original query took 7 hours to run and there were no records in the original data, so I made up this test data and got messed up. Thank you so much

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1957 views
  • 0 likes
  • 2 in conversation