If you want to avoid the intricacies of intnx and intck functions, you could simply do:
Proc sql;
create table final as
select
a.gvkey,
a.datadate,
max(b.revt) as maxRevt
from
data as a inner join
data as b on a.gvkey=b.gvkey and
year(b.datadate) between year( a.datadate) -4 and year( a.datadate) -1
group by a.gvkey, a.datadate;
quit;
... View more