I attempted to calculate a formula based on price at different time (). More specifically, 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 .
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.
Shouldn't it be
if other_ric=_ric and other_time > new_time+300 and other_date = date_l_ then do;
Shouldn't it be
if other_ric=_ric and other_time > new_time+300 and other_date = date_l_ then do;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.