-
Notifications
You must be signed in to change notification settings - Fork 3
/
WRDS_batch_ticker_cq.sas
52 lines (38 loc) · 1.67 KB
/
WRDS_batch_ticker_cq.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
filename input '/home/yale/genli925/cq_tsymbol_date.txt'; /* Change to your input file path */
data dictionary2;
infile input dlm = "," dsd missover;
input smbl $ dates yymmdd8.;
run;
/* Genrate a macro variable to loop through */
proc sql noprint;
select distinct dates into :datesValsM separated by ' ' /* select unique dates that we want to extract from TAQ Monthly*/
from work.dictionary2
where dates < '01Jan2013'd;
quit;
%put &datesValsM;
/* A macro that autogenerated list of needed Monthly TAQ datasets */
%macro taq_monthly_dataset_list(type = );
%let type=%lowcase(&type);
%let i = 1;
%let datesValsMi = %scan(&datesValsM, &i);
/* Loop over each date in "datesVals" macro variable*/
%do %while("&datesValsMi" ~= "");/** For each date in the "datesVals" */
%let yyyymmdd=%sysfunc(putn(&datesValsMi,yymmddn8.));
/*If the corresponding dataset exists, add it to the list */
%if %sysfunc(exist(taq.&type._&yyyymmdd)) %then taq.&type._&yyyymmdd;
%let i = %eval(&i + 1);
%let datesValsMi = %scan(&datesValsM, &i);
%end;
%mend;
* using this macro;
data outputM;
set %taq_monthly_dataset_list(type = cq) open=defer; /* get TAQ Monthly data for desired dates */
where (time between '9:30:00't and '10:30:00't) or (time between '15:00:00't and '16:00:59't);
run;
proc sql;
create table outputM as select a.*, b.*
from (select * from work.dictionary2 where dates < '01Jan2013'd) a, outputM b
where a.smbl = b.symbol and a.dates = b.date;
quit;
/* optional: export sas7bat file to dta file */
proc export data = outputM outfile= '/home/yale/genli925/ticker_cqm/ticker_cq_missing_tsymbol.dta'; run;