time series - SAS: Insert Blank Rows -


i'm calculating interval statistics (standard deviation of 1 minute intervals example) of financial time series data. code managed results intervals contain data, intervals not contain observations in time series, i'd insert empty row maintain timestamp consistency.

for example, if there's data between 10:00 10:01, 10:02 10:03, not 10:01 10:02, output be:

10:01 stat1 stat2 stat3 10:03 stat1 stat2 stat3 

it ideal if result (i want values 0, missing '.'):

10:01 stat1 stat2 stat3 10:02 0     0     . 10:03 stat1 stat2 stat3 

what did:

 data v_temp/view = v_temp;     set &taq_ds;     time_m between &start_time , &end_time;     intv = hms(00, ceil(time_m/'00:01:00't),00); *create 1 minute interval;     format intv tod.; *format hh:mm:ss;  run;    proc means data = sorted noprint;     sym_root date intv;     var price;     weight size;     output      out=oneminstats(drop=_type_ _freq_)      n=ntrades  mean=vwap sumwgt=sumshs max=hi min=lo std=sigmaprc     idgroup(max(time_m) last out(price size ex time_m)=lasttrd lastsize lastex lasttime);  run; 

for non-active stocks, there're many gaps this. efficient way generate filling rows?

if have sas:ets licensed, proc expand choice adding blank rows in time series. here's short example:

data mydata; input timevar stat1 stat2 stat3; format timevar time5.; informat timevar hhmmss5.; datalines; 10:01 1 3 5 10:03 2 4 6 ;;;; run;  proc expand data=mydata out=mydata_exp from=minute to=minute observed=beginning method=none; id timevar; run; 

the documentation has more details if want perform inter/extrapolation or that. important options from=minute, observed=beginning, method=none (no extrapolation or interpolation), , id (which identifies time variable).

if don't have ets, data step should suffice. can either merge known dataset, or add own rows; size of dataset determines easier. here's merge variation. add own rows in datastep variation similar how create rows.

*select maximum time available.; proc sql noprint; select max(timevar) :endtime mydata; quit;  *create empty dataset times; data mydata_tomerge; set mydata_tomerge(obs=1); timevar = timevar &endtime 60; *by 60 = minutes!; output; end; keep timevar; run; *now merge 1 times 1 data!; data mydata_fin; merge mydata_tomerge(in=a) mydata; timevar; if a; run; 

Comments