Monday, 15 July 2013

datetime - SAS Time Interval Data -



datetime - SAS Time Interval Data -

so have dataset trading info has been merged block trades, big trades happening @ 1 time , executed big financial establishment of kind.

i trying see how cost of security moves right after block trade in minutes before , after block trade.

the info has variable called date_time has date , time , formatted this: 08feb03: 03:20:00 (which feb 8th 2003 @ 3:20:00 am). has dummy variable when trade classified block trade, says "block" if block trade , missing if not block trade.

what find every block trade , create variable has time lapse after , before block trade. instance, if block trade happened @ 3:20 on feb 8th 2010 want @ cost @ trades executed right before (lets @ time 3:16 , time 3:19 if trades right before) , right after (such @ 3:21 , 3:23 if trades right after). right trying @ 30 min intervals. hence info

date_time|block|price|time_from_block_trade 08feb08:03:16:00 "." 113.01 -4 08feb08:03:19:00 "." 113.02 -1 08feb08:03:20:00 "block" 113.02 0 08feb08:03:21:00 "." 113.07 1 08feb08:03:23:00 "." 113.09 3

i have except don't know how create time_from_block_trade variable @ all. there bunch of block trades in dataset , figure out how create variable has difference in date_time between block trade , trades occurred right before , right after block trade.

i tried doing proc expand can't seem figure out. sorry if easy brand new @ sas.

the straightforward way approach might split few pieces.

first, have dataset of block trades. assume have other variables on there identify trade specifically, , not datetime (since trades can simultaneous downwards microsecond, if understand correctly)? if not assume know how original dataset and/or can create unique id. let's called stockid.

data blocks; set trades; if block=1; maintain stockid date_time block_id; rename date_time=block_time; block_id+1; run;

now merge original dataset.

proc sql; create table block_trades select t.*, b.block_id, t.date_time - b.block_time time_from_block_trade blocks b left bring together trades t on b.stockid=t.stockid , abs(b.block_time -t.date_time) le 30 order b.block_id, t.date_time; quit;

this should easy analyze dataset useful rows, block_id by-group analysis (or class), , time block calculated you.

this works using initial dataset, else replicating this:

data trades; phone call streaminit(7); stockid=1 5; date_time = '01jan2014:10:00:00'dt '01jan2014:13:00:00'dt; volume = 1000*rand('uniform'); if volume > 999 block=1; else block=0; output; end; end; run;

datetime sas time-series

No comments:

Post a Comment