data a;
input group $ indexyear Pair_ID;
cards;
case 2011 0000048810
control 2009 0000048810
control 2006 0000048810
control 2007 0000145478
control 2010 0000145478
case 2013 0000145478
case 2010 0000151800
control 2013 0000151800
control 2007 0000151800
control 2010 0000151800
control 2012 0000151800
control 2011 0000151800
;
run;
proc sort data=a; by Pair_ID group indexyear;run;
data b;
set a;
by Pair_ID group indexyear;
if first.Pair_ID then do;
benchyear=indexyear;
end;
retain benchyear;
dif=abs(indexyear-benchyear);
run;
proc sort data=b(where=(group="control")) ; by Pair_ID dif;run;
proc sort data=b nodupkey ; by Pair_ID;run;
结果: