[code:3tkfys4c]data _temp(index=(id date));
input ID $ Date yymmdd8. profit net_profit;
format Date yymmdd10.;
cards;
001 09-07-20 -2.3 12.5
001 09-07-19 0.2 .
001 09-07-18 1.3 .
001 09-07-17 4.7 .
001 09-07-16 -1.2 .
;
data _out(drop=lag_net_profit);
do until(last.id);
set _temp;
by id descending date;
if not first.id then net_profit=sum(lag_net_profit,profit);
output;
lag_net_profit=net_profit;
end;
run;[/code:3tkfys4c]
[quote="hopewell":xiacvupq][code:xiacvupq]data _temp(index=(id date));
input ID $ Date yymmdd8. profit net_profit;
format Date yymmdd10.;
cards;
001 09-07-20 -2.3 12.5
001 09-07-19 0.2 .
001 09-07-18 1.3 .
001 09-07-17 4.7 .
001 09-07-16 -1.2 .
;
data _out(drop=lag_net_profit);
do until(last.id);
set _temp;
by id descending date;
if not first.id then net_profit=sum(lag_net_profit,profit);
output;
lag_net_profit=net_profit;
end;
run;[/code:xiacvupq][/quote:xiacvupq]