data stocks (drop=pstock1-pstock3); infile 'c:\temp\3stock.txt'; retain pstock1-pstock3 0; input stock1-stock3; ret1=(stock1-pstock1)/pstock1; ret2=(stock2-pstock2)/pstock2; ret3=(stock3-pstock3)/pstock3; pstock1=stock1; pstock2=stock2; pstock3=stock3; if _n_=1 then do; ret1=0; ret2=0; ret3=0; end; data haim (drop= ret1-ret3); file print; set stocks (drop=stock1-stock3) end=last; retain cur(1); retain equity(1000); if cur=1 then dayret=ret1; if cur=2 then dayret=ret2; if cur=3 then dayret=ret3; equity=equity*(1+dayret); if max(of ret1-ret3)=ret1 then cur=1; if max(of ret1-ret3)=ret2 then cur=2; if max(of ret1-ret3)=ret3 then cur=3; if last then put 'Haims final equity is ' equity; proc print; run;