PROC SQL left join on id and date not working

40 views Asked by At

I am trying to merge two tables with below code:

proc sql;
create table test as
select a.*, b.*
from aaa a
left join bbb b on a.id=b.id and a.date1<=b.date2;
quit;

But the output shows blanks in columns from table b.

However if I change it to a.date1>=b.date2 it seems to work. Why would this be happening?

Checks I have done to be sure: 1) date formats are ok; 2) there are dates in table aaa which are less and more than table b dates. Please help!

1

There are 1 answers

0
siddop3 On
proc sql;
create table test as
select a.*, b.*
from aaa a
left join bbb b on a.id=b.id and datepart(a.date1)<=datepart(b.date2);
quit;

ok so looks like when I add datepart to both dates it works perfectly fine. Hopefully this will come in handy to someone.