BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Neal0801
Obsidian | Level 7

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

1 REPLY 1
PGStats
Opal | Level 21

Shouldn't it be

 

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

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 411 views
  • 1 like
  • 2 in conversation