BookmarkSubscribeRSS Feed
adrian_waw
Calcite | Level 5
Hi, I'm having problems trying to include time into my conditions.

variables are:
date, date_time (date with time), trade_price, bid_price, ask_price

conditions are:
- when there is a trade price, we want to compare which (bid price OR ask price) is closer to trade price.
- When bid price is closer to the trade price, we will consider it as 'sell' and when ask price is closer to the trade price, we will consider it as 'buy'
- The age of the bid or ask price has to be at least 5 seconds and at most 30 minutes old to be considered.

Some examples:
- Suppose there are two bid and ask prices (5 seconds old and 6 seconds old). We will choose the latest quote which will be the 5sec bid and ask price and compared it to the current trade price.
-Suppose there is a bid/ask that happened 10 secs ago, and one that just occurred 4 secs ago, we will choose the 10 second bid/ask price to be compared. However in one second time, we will use the most recent bid/ask price (which was previously 4 seconds ago).

My problem is to include time into my argument. Heres my coding so far as i don't know how to include the above conditions.

data data_new1;
set data_timestamp1;
if price ^= "." then do;
if abs(bid_price-trade_price) < abs(ask_price-trade_price) then sell=1;
else buy=1;
end; run;

Appreciate any help I can get. Thanks in advance. Message was edited by: adrian.waw
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You have the TIMEPART function and also possibly the LAG function to consider using, however I would expect that you have some other "BY variable list" to consider for each "item" with your analysis - that's not shown in your Excel file.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic/post:

timepart function site:sas.com
lag function site:sas.com
by group processing site:sas.com

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1010 views
  • 0 likes
  • 2 in conversation