Select observation at t+5

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Select observation at t+5

I attempted to calculate a formula based on price at different time (enter image description here). More specifically,enter image description here donates the first price observed at least 5 minutes after the price which is measured.

The following code is used to create a variable that represents enter image description here.

 

 

data WANT;
set  HAVE nobs=nobs;
do _i = _n_ to nobs until(other_date > date_l_);
    set  HAVE(
        rename=(    _ric=other_ric
                    date_l_= other_date 
                    price = other_price 
                    new_time = other_time)
        keep=_ric date_l_ price int1min new_time) 
        point=_i;
    if other_ric=_ric and new_time > new_time+300 and other_date = date_l_ then do;
        new_price = other_price;
        leave;
        end;
    end;
drop other_: ;
run;    

However, the code did not work correctly at all time. As shown in the pic, the new_price is correct in green rectangle but is incorrect in red rectangle. Could anyone help me to solve this problem? I attached a sample of data as well. 

 

enter image description here

 

 


Accepted Solutions
Solution
‎02-28-2018 06:39 PM
Esteemed Advisor
Posts: 5,543

Re: Select observation at t+5

Shouldn't it be

 

if other_ric=_ric and other_time > new_time+300 and other_date = date_l_ then do;

PG

View solution in original post


All Replies
Solution
‎02-28-2018 06:39 PM
Esteemed Advisor
Posts: 5,543

Re: Select observation at t+5

Shouldn't it be

 

if other_ric=_ric and other_time > new_time+300 and other_date = date_l_ then do;

PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 91 views
  • 1 like
  • 2 in conversation