Hi there, I am looking for the shortest positive date difference. But if the date difference value is negative and is smaller than shortest postive date difference then I want the negative difference . In other word, out of the following date differences: 5, 2, -3: I want to flag 2 [as 2 is shortest positive and is less than (-)3] whereas out of the following date differences: 5, 4, -3: I want to flag -3 [as 4 is shortest but is more than (-)3 ] . I am having difficult at my final step of my SAS code. data test1;
input id date1 $9. date2 $9. ;
cards;
1 11012016 13012016
1 11012016 15012016
1 11012016 10012016
1 11012016 11012016
2 11012016 20012016
2 11012016 15012016
2 11012016 16012016
2 11012016 08012016
;
run;
data test2;
set test1 (rename= (date1=date3 date2=date4));
date1=input(put(date3, 8.), ddmmyy8.);
date2=input(put(date4, 8.), ddmmyy8.);
format date1 date2 date9.;
date_diff=intck('DAY', date1, date2);
run;
proc sort data =test2 ; by id date_diff; run;
Can somebody help me with this. Thank you in advance for your kind reply.
... View more