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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 913 views
  • 0 likes
  • 2 in conversation