Here's a solution, if want you mean by age is 15 days then you do not need the function, if you want month or years just replace day with what you want: data have; infile cards dsd; length defect $10.; informat col1 yymmdd8.; format col1 mmddyy10.; input BODYNO$ DEFECT$ ADJKM former_variable$ former_label $ COL1; cards; 0NP07185,99600668MP,15332,DREP,DREP,20130116 0NP07185,99600668MP,29407,DREP,DREP,20131029 0NP07185,99600668MP,41802,DREP,DREP,20140602 0NP07185,99600668MP,51477,DREP,DREP,20141222 0VU43599,99600668MP,15572,DREP,DREP,20130227 0VU43599,99600668MP,29010,DREP,DREP,20130619 0VU43599,99600668MP,44477,DREP,DREP,20131114 0VU43599,99600668MP,59886,DREP,DREP,20140614 0VU43599,99600668MP,72938,DREP,DREP,20150325 8DN12628,99600668MP,74186,DREP,DREP,20100727 8DN12628,99600668MP,101807,DREP,DREP,20110919 8DN12628,99600668MP,126877,DREP,DREP,20120229 8DT43009,99600668MP,18829,DREP,DREP,20091215 8DT43009,99600668MP,18999,DREP,DREP,20100514 8DT43009,99600668MP,40864,DREP,DREP,20110912 8DT43009,99600668MP,50756,DREP,DREP,20111129 8DT43009,99600668MP,66477,DREP,DREP,20120822 8DT43009,99600668MP,77629,DREP,DREP,20130823 8DT43009,99600668MP,87800,DREP,DREP,20140805 8DT43009,99600668MP,90984,DREP,DREP,20150407 ; run; proc sort data=have;by bodyno defect; data all want; set have; format l_col1 mmddyy10.; by bodyno defect; l_adjkm = lag(adjkm); l_col1 = lag(col1); if not first.bodyno then do; diff_adjkm = adjkm - l_adjkm; diff_date = intck('day',l_col1,col1); end; output all; if diff_adjkm > 10000 and diff_date > 15 then output want; run;
... View more