For your second question.
data temp;
if _n_=1 then do;
if 0 then set components;
declare hash h(dataset:'components',hashexp:20);
h.definekey('Year',' Components');
h.definedone();
end;
set products;
do year=BeginYear-5 to BeginYear-1; /*<------------*/
if h.check()=0 then do;found=1;leave;end;
end;
drop year;
run;
proc sql;
create table temp2 as
select FirmID,BeginYear,ProductID,ifn(sum(found)>0,1,0) as flag
from temp
group by FirmID,BeginYear,ProductID ;
create table want as
select FirmID,BeginYear,sum(flag) as nb_Incremental,sum(flag=0) as nb_Radical
from temp2
group by FirmID,BeginYear ;
quit;
... View more