I have written code to run through data for specified dates. The problem I have is that I have to repeat the same procedure for multiple dates. My understanding is I can create a loop in which SAS will iterate the same procedure and generate output for multiple dates. Below is the subset of the code I have written. /* STEP 1: RETRIEVE DAILY TRADE AND QUOTE (DTAQ) FILES */
libname ct '/wrds/nyse/sasdata/taqms/ct';
/* Retrieve Trade data */
data DailyTrade;
/* Enter Trade file names in YYYYMMDD format for the same dates */
set ct.ctm_20140425 ct.ctm_20140426;
/* Enter the same company tickers as above */
where sym_root in ('AA','AAL')
/* Retrieve trades during normal market hours */
and (("7:00:00.000000000"t) <= time_m <= ("20:00:00.000000000"t));
type='T';
format date date9.;
format time_m part_time trf_time TIME13.;
run;
/* STEP 2: CLEAN DAILY TRADES DATA - DELETE ABNORMAL TRADES */
data trade2;
set DailyTrade;
where Tr_Corr eq '00' and price gt 0;
drop Tr_Corr Tr_Source TR_RF Part_Time RRN TRF_Time Sym_Suffix Tr_SCond
Tr_StopInd;
run;
/* STEP 3: remove seconds/miliseconds */
data trade2;
set trade2;
rtime = time_m - mod(time_m,60);
format rtime: time13.;
run;
/* STEP 4: calculate simple average by minute */
proc means data=trade2 noprint;
by date rtime sym_root;
var price;
output out=simple_avg(drop=_type_ _freq_) mean=simple_mean;
run;
data trade2;
merge trade2 simple_avg;
by date rtime sym_root;
run;
/* STEP 5: calculate weighted average by minute */
proc summary data=trade2 noprint;
by date rtime sym_root;
var price;
weight size;
output out=weight_avg(drop=_type_ _freq_) mean=weight_mean;
run;
data trade2;
merge trade2 weight_avg;
by date rtime sym_root;
run;
/* STEP 6: duplicates drop */
proc sort data=trade2
out=trade3
nodupkeys;
by date rtime sym_root;
run;
/* STEP 7: 5min (15m, 30m) -interval return computation */
data temp;
set trade3;
run;
proc sql;
create table ret5 as
select *,(((select weight_mean from temp where date=a.date and sym_root=a.sym_root and rtime-300=a.rtime)-weight_mean)/weight_mean) as ret5, date, sym_root, rtime
from temp as a;
quit;
data trade3;
merge trade3 ret5;
by date rtime sym_root;
run;
proc sql;
create table ret15 as
select *,(((select weight_mean from temp where date=a.date and sym_root=a.sym_root and rtime-900=a.rtime)-weight_mean)/weight_mean) as ret15, date, sym_root, rtime
from temp as a;
quit;
data trade3;
merge trade3 ret15;
by date rtime sym_root;
run;
proc sql;
create table ret30 as
select *,(((select weight_mean from temp where date=a.date and sym_root=a.sym_root and rtime-1800=a.rtime)-weight_mean)/weight_mean) as ret30, date, sym_root, rtime
from temp as a;
quit;
data trade3;
merge trade3 ret30;
by date rtime sym_root;
run;
data project.DailyTrade;
set trade3;
run; If you look at the code, I have specified the dates of interest. Can anyone help me loop through the dates for multiple dates? *I have dates of interest in my excel file. **I want individual output (DailyTrade) for each date.
... View more