Page 1 of 1

%if statements in dofor loops?

Posted: Fri Oct 02, 2015 11:45 pm
by e1983
Hi. I trying to figure out a bug in my code. I have 100 or so series and I am trying to clean up any missing values.I am trying to use the following code. If I use the dofor loop, I only get a column of 1s. If I use the code outside of the loop, the Na observation is fixed according to the %if statement. Can %if statements not be used inside of a dofor loop? Any help would be greatly appreciated.


dofor i = RPI
set %s(%l(i)) = %if(%valid(i), i, (i{1} + i{-1})/2)
end
set rpi = %if(%valid(rpi), rpi, (rpi{1} + rpi{-1})/2)

Re: %if statements in dofor loops?

Posted: Sat Oct 03, 2015 8:15 am
by TomDoan
You need i{0} to get the current value of the series for the DOFOR index.

Re: %if statements in dofor loops?

Posted: Sat Oct 03, 2015 8:08 pm
by e1983
Thanks. Works perfectly now. Much appreciated.