DATA Step, Macro, Functions and more

remove short peaks and troughs in time series

Reply
Frequent Contributor
Posts: 78

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: 17,784

Re: remove short peaks and troughs in time series

Do you have SAS/Stat or ETS? 

 

You can check with the following:

 

proc setinit;

run;

Frequent Contributor
Posts: 78

Re: remove short peaks and troughs in time series

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

Re: remove short peaks and troughs in time series


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: 9,671

Re: remove short peaks and troughs in time series

Valued Guide
Posts: 797

Re: remove short peaks and troughs in time series

[ Edited ]

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;

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 133 views
  • 0 likes
  • 4 in conversation