BookmarkSubscribeRSS Feed
JHuttunen
Calcite | Level 5

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!

1 REPLY 1
data_null__
Jade | Level 19

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;

  

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 842 views
  • 0 likes
  • 2 in conversation