07-15-2016 10:12 AM
Hi I have this code
array returns SPY--AFL;
do i= 1+&K to dim(returns);
I would like the return computation to start at row 1+K and have the previous rows blank but it starts at column 1+K with the stock prices shown for previous columns.
What am I doing wrong?
Thanks in advance.
07-15-2016 01:49 PM
The automatic variable _n_ has the row number and can be used for such processing:
data thesis.test7; set thesis.test2; array returns SPY--AFL; if _n_ > &k then do i= 1 to dim(returns); returns[i]=(returns[i]-lag(returns[i]))/lag(returns[i]); end; run;
HOWEVER, the lag function, when it executes for row 7 all the lagged values will be missing because that is the first time the lag function is called.
You might be better off creating an array of non-conditional lagged values and reference that array instead of using lag(returns[i])
07-15-2016 03:23 PM
07-15-2016 03:58 PM
To you mean to reverse the order of processing (AFL first and SPY last)? Easiest would be to change the index of the do loop:
Do i = dim(returns) to 1 by (-1);
If you are thinking of something else you may need to go into more details and the reasons why. Preferrably in a separate topic.