04-13-2016 04:11 AM
Please guide me in calculation of SAS Exponential Moving average for N=22 days without using SAS ETS software (Proc expand Procedure)
Please let me know the formula or logic.
As of I browsed, the formula is, EMA =( (close price)-Previous day EMA)*smoothing constant)+Previous day EMA.
Thanks, I got some valuable answer from USers of this group.
please see my below code,
data EMA2c(keep=symbol date1 close a22 ema22 lema22 count ma22 );
by symbol date1;
if count eq 22 then do;EMA22=ma22;end;
/* EMA Calculation */
if count gt 22 then do;EMA22=((close-lema22)*a22)+lema22;end;
If I code as above, for 23rd and 24th observation, the 22nd EMA value is getting populated(that is lag value of 22nd observation is populated twice), so that other values from 25 are moving down one step though lagging correctly.why this 22nd observation is lagging twice for 23rd and 24th observations? for 23rd observation it can come, for 24th observation,23rd EMA value has to be populated. So confused....
04-13-2016 05:47 AM - edited 04-13-2016 05:48 AM
Where is your data and output ?
do stock=1 to 10;
do date=1 to 100;
if first.stock then do;n=0;ema=.;end;
if n=22 then ema=price;
else if n gt 22 then ema= price*&constant + (1-&constant)*ema;
04-13-2016 10:01 PM