Help using Base SAS procedures

Deleting stale observations from time series data

Reply
N/A
Posts: 1

Deleting stale observations from time series data

Hi

I have a stock price data, which has a problem that after the company is delisted, the price is set to last market price for the rest of the sample.

So let's consider a simplified example data:

DATE    PRICE

1995     3

1996     4

1997     2

1998     2

1999     2

2000     3

2001     4

2002     5

2003     2

2004     2

2005     2

2006     2

The company was delisted in 2004 but the value is set stale at the last market price. All the observations after 2003 should be deleted.

I added another column "lastprice" to the data set with a fixed last price observation value.

I currently have something like:

if price=lag(price) then

     if price=lastprice then delete;

But this code would delete 1998 and 1999 data from the example above even though they are valuable info.

I should be somehow be able to refer to the rest of the values within a data set, but do not know how it's done.

Do you guys have an idea how i would be able to remove the stale data from the time series as described above?

Thanks in advance!

Respected Advisor
Posts: 3,799

Re: Deleting stale observations from time series data

Posted in reply to JHuttunen

This works for your sample data, but is your sample data representative of you actual data.

data stale;
   input DATE PRICE;
   d = dif(price);
  
cards;
1995     3
1996     4
1997     2
1998     2
1999     2
2000     3
2001     4
2002     5
2003     2
2004     2
2005     2
2006     2
;;;;
   run;

data stale2;
   do _n_ = 1 by 1 until(eof1);
      set stale end=eof1;
      by d notsorted;
     
if first.d and d eq 0 then _obs_=_n_;
      end;
  
do _n_ = 1 by 1 until(eof2);
      set stale end=eof2;
      if _n_ lt _obs_ then output;
     
end;
  
stop;
  
run;

  
Ask a Question
Discussion stats
  • 1 reply
  • 192 views
  • 0 likes
  • 2 in conversation