data a;
input id date :date9.;
format date date9.;
cards;
123 31JAN2014
123 31JUL2014
123 31AUG2014
222 31MAR2014
222 30APR2014
333 30JUN2014
421 28FEB2014
235 31MAR2014
991 31MAY2014
991 31OCT2014
991 31DEC2014
;
run;
data b;
input id date : date9. membership $;
format date date9.;
cards;
123 28FEB2014 PURPLE
123 30APR2014 BRONZE
123 31JUL2014 SILVER
123 31DEC2014 GOLD
222 28FEB2014 PURPLE
222 31MAR2014 BRONZE
222 30JUN2014 SILVER
235 28FEB2014 SILVER
235 31MAY2014 GOLD
;
run;
proc sql;
create table want(drop=dif) as
select a.*,b.date as date2,b.membership,abs(a.date-b.date) as dif
from a left join b
on a.id=b.id
group by a.id,a.date
having calculated dif=min(calculated dif);
quit;
Xia Keshan
... View more