Help using Base SAS procedures

how to include time constraints into the conditions

Reply
Occasional Contributor
Posts: 7

how to include time constraints into the conditions

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
Occasional Contributor
Posts: 7

Re: how to include time constraints into the conditions

Posted in reply to adrian_waw
Heres the screenshot of the excel file:
http://img39.imageshack.us/img39/6109/helpinsas1.jpg
Super Contributor
Super Contributor
Posts: 3,174

Re: how to include time constraints into the conditions

Posted in reply to adrian_waw
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
Ask a Question
Discussion stats
  • 2 replies
  • 92 views
  • 0 likes
  • 2 in conversation