My previous code did not count for missing values, it produced table with 513 obs, however, under my settings (SAS 9.2, winxp sp3), it did not alarm any cartisian warnings. So are you using a learning version of SAS? After a minor tweak to acount for the missing values, it outcomes a table with 341 obs. proc sql; create table final3 as select distinct * from FLoat_Leg_fr_GDR (where=(not missing (prev_cpn_date))) a left join lib3rate b on 1 group by a.prev_cpn_date having abs(a.prev_cpn_date-b.AS_OF_DATE)<= min(abs(a.prev_cpn_date-b.AS_OF_DATE) ) ; quit; The reason it has 341 obs instead of 337 is that there are some records have the same date difference between pre and post obs, so they BOTH get to be kept. I wonder if SQL can actuall chose pre or post obs when there is a tie. The benefit of SQL is that data does not need to be pre-sorted, and SQL in this case, will deliver most accurate results just in term of minimum differences. Regards, Haikuo
... View more