data result;
set have;
if obs<5 then money=100;
retain last_money;
lag_money=lag(money);
lag_close=lag(close);
lag_own=lag(own);
if lag_money ne . then last_money=lag_money;
if obs>=5 and buy=1 then money=last_money;
if obs>=5 and sell=1 then money=last_money*close/lag_close;
if obs>=5 and buy=0 and sell=0 and lag_own=1 then money=last_money*close/lag_close;
if obs>=5 and buy=0 and sell=0 and lag_own=0 then money=last_money;
last_money=money;
drop lag: last:;
run;