I agree with you the format should not influence, i ran the code again with the earlier format yymmn6. that you used and i get the same result
data have_base;
input company$ _date:$6. profit;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199701 5
a 199606 9
b 201404 6
f 200004 78
;
run;
data have_event;
input company$ _date:$6. EPS;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199608 5
a 199706 30
a 199605 4
a 199712 9
a 199806 10
c 201404 6
k 200004 78
n 198607 56
a 198504 3
b 201304 3
b 201305 6
b 201306 8
b 201504 80
b 201603 5
;
run;
proc sort data=have_event;
by company;
run;
proc sql;
create table test as select a.*,b.eps,b.date as date_event from have_base as a, have_event as b where intnx('month',a.date, -12)<=b.date<=a.date
and a.company=b.company;
quit;
... View more