Yeah. if an individual obs represent one year, you can combine LAG skill and MERGE skill together . Like :
data want;
merge have
have(firstobs=2 keep=CUSIP Annret rename=(CUSIP=CUSIP1 Annret=Annret1))
have(firstobs=3 keep=CUSIP Annret rename=(CUSIP=CUSIP2 Annret=Annret2));
lag1=lag(Annret);
lag2=lag2(Annret);
if CUSIP=lag(CUSIP) and CUSIP=lag2(CUSIP) then FORMRET=sum(Annret,lag1,lag2);
if CUSIP=CUSIP1 and CUSIP=CUSIP2 then EVALRET=sum(Annret,Annret1,Annret2);
run;
... View more