## remove short peaks and troughs in time series

Regular Contributor
Posts: 210

# remove short peaks and troughs in time series

I only have base sas and wonder and have exhaustive daily values for some time series. Just curious, is there an easy way to remove short peaks and throughs. Here shortness is defined by a parameter n representing the number of days)?

Super User
Posts: 23,980

## Re: remove short peaks and troughs in time series

Posted in reply to csetzkorn

Do you have SAS/Stat or ETS?

You can check with the following:

proc setinit;

run;

Regular Contributor
Posts: 210

## Re: remove short peaks and troughs in time series

Thanks. Have SAS/Stat but as I said not ets.
Super User
Posts: 23,980

## Re: remove short peaks and troughs in time series

Posted in reply to csetzkorn

csetzkorn wrote:
Thanks. Have SAS/Stat but as I said not ets.

Your initial posts say Base SAS, nothing about ETS/IML/STAT modules.

One way remove peaks/throughs is a moving average. Determine your cycle length and then apply a moving average.

For the moving average calculation you can use a temporary array method illustrated

http://support.sas.com/kb/41/380.html

If you have IML, you have more options but it means doing the math yourself that having the ability to use the predesigned procedures.

Super User
Posts: 10,848

## Re: remove short peaks and troughs in time series

Posted in reply to csetzkorn
Posts: 1,389

## Re: remove short peaks and troughs in time series

[ Edited ]
Posted in reply to csetzkorn

Let's say you have daily data sorted by PERMNO (a stock identifier) and DATE.  You want 15-day moving averages of PRICE, but will accept window sizes as small as 10-days:

``````%let winsiz=15;
%let minwin=10;

data want;
set have;
by permno;

if first.permno then do;
NDays=0;
sum_price=0;
end;
if NDays<&winsiz then NDays+1;

sum_price + price - ifn(NDays>&winsiz,lag&winsiz(price),0);
if NDays>=&minwin;
mean=sum_price/NDays;
run;``````

Discussion stats
• 5 replies
• 184 views
• 0 likes
• 4 in conversation