I am trying to make this code work but for some reason it gives me a lot of duplicates. Table1 has 75k records and I would like to get data from Table2 against each row. Please help me:
proc sql;
create table table3 as
select a.*, b.*
from table1 as a
left join table2 as b on a.username=b.username and datepart(a.date)>=datepart(b.date)
group by a.username, a.id, b.date
having b.date = max(b.date);
quit;
If I add this code below the above code then I get the desired result but its not an efficient way of doing this. Ideally the desired results should come from the merge code.