Question about Dow-Loop SAS code
Posted: 05 May 2012 04:58 PM   [ Ignore ]
Newbie
Rank
Total Posts:  5
Joined  2012-05-03

Dear Joost,


I am trying to run a code provided by WRDS on this link.  First I wanted to check the example straight ahead. I am pretty new to SAS but I have read some manuals and staff about dow-loop as well, including the notes on the website (which are pretty exhaustive), but I get the error. I will be so grateful if you could point me to what is wrong with the code. I will appreciate your help so much!

the link of the code: http://wrds-web.wharton.upenn.edu/wrds/research/applications/microstructure/sas dow loop/

the code:

data matched /*Line 1*/
(drop cqsymbol cqdate cqtime bid bidsiz ofr ofrsiz lagged_match timediff
   exact_match rbid rofr rcqdate cqtime rcqtime rcqsymbol
rename 
=  (mbid=BID mofr=OFR)
sortedby symbol date time);
attrib CQSYMBOL length=$10. /*Line 2*/
attrib RCQSYMBOL length=$10./*Line 3*/
retain CQSYMBOL RCQSYMBOL CQDATE RCQDATE CQTIME RCQTIME BID RBID OFR ROFR 
end_of_quotes_file
;  /*Line 4*/
 
set taq.ct_19980102 (where = (time >= '9:30:00'T  AND  time <= '16:00:00'T)) ;  /*Line 5*/
do until (exact_match OR lagged_match OR end_of_quotes_file ); /*Line 6*/
if symbol>cqsymbol OR (symbol cqsymbol AND date cqdatethen
  go to READQUOTE
/*Line 7*/
else /*Line  9-12*/
if cqsymbol symbol OR cqdate>date then do; lagged_match=1;go to END TIMEOKLOOP;End;
else do; 
TIMEDIFF time cqtimeTIMEDIFF time cqtime/*Line 13-15*/
if timediff 5 then exact_match 1/*Line 16-25*/
else if timediff 5 then lagged_match 1;
else do;
  
READQUOTE: ;
  
RCQSYMBOL CQSYMBOL;
  
RCQDATE CQDATE;
  
RCQTIME CQTIME;
  
RBID BID;
  
ROFR OFR;
 
set taq.cq_19980102 (rename = (symbol=CQSYMBOL date=CQDATE time=CQTIME/*Line 26-30*/
where=(cqtime>='9:30:00'AND cqtime<='16:00:00'AND ofr>AND (ofr-bid)/bid<= 0.1))
end end_of_quotes_file ;end;endEND TIMEOKLOOP: ; end
/*Line 31-37: Depending on the break point encountered above, select the match array*/
if exact_match then do;
   
MBID bid;  label mbid 'Matching Bid Price';
   
MOFR ofr;  label mofr 'Matching Offer Price' ;
   
MTIME cqtimeformat mtime time. ;  label mtime 'Time of the Matching Quote' ;
   
Output;end;
else if 
lagged_match then do; /*Line 38-46*/
  
if symbol rcqsymbol then do;MBID rbid;MOFR rofr;MTIME rcqtime;output;End;
else do; 
MBID = .; MOFR = .; MTIME = .; output;End;end;             /*Line 47-54*/
else if end_of_quotes_file then do;MBID=.;MOFR=.;MTIME=.;Output;end;/*Line 55-62*/
run

 

and the error is about these two parts

20   if cqsymbol symbol OR cqdate>date then do; lagged_match=1;go to END
20 
TIMEOKLOOP;End;
     ----------
     
79
     202
ERROR 79
-322Expecting a ;.

ERROR 202-322The option or parameter is not recognized and will be ignored
34   end end_of_quotes_file ;end;endEND TIMEOKLOOP: ; end;
                                            ----------      ---
                                            
79              161
ERROR 79
-322Expecting a ;.

ERROR 161-185No matching DO/SELECT statement

where exactly is the semicolon expected and missed? or where is the mistake.

and also about this whole part of the code go to END TIMEOKLOOP;, why is it here (and is it correctly provided?) it is not explained so clearly on the website..


Thank you in advance for your help. I desperately need this code to work for my thesis.

 

Profile
 
 
Posted: 06 May 2012 10:42 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi Npap,

I have not worked with TAQ before, but I am interested in figuring out how it works.
I ran the code, and get the same errors as you do.
I know about the DOW loop, and how ‘fantastic’ it is, but this code is hard to understand (lines like ‘end = end_of_quotes_file ;end;end; END TIMEOKLOOP: ; end;’ are mind-boggling).

I believe the ‘research’ pages on wrds were added recently (as are the macros).  Would you mind posting this question on wrds ‘community’ pages?

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 06 May 2012 11:04 AM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  5
Joined  2012-05-03

Dear Joost,

thank you very much for your reply.

well, I just checked the community webpage, I did not know it before.  I will post the question there as well, thanks.

in the meanwhile. just by removing that part about TIMEOKLOOP in both places the code was run without any errors..

Now I am trying to figure out whether the output is what it should be, which is not easy actually:)


There will definitely be an error in the output by removing that part, right? how do you think?

thanks again!

Profile
 
 
Posted: 06 May 2012 11:19 AM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi Npap,

Ok, thanks. Maybe use ‘A’ and ‘AAA’ for 1/2/2001, since there is some output for these tickers on the WRDS TAQ page.

Hopefully, the WRDS support people can tell what is going on. The DOW loop is supposed to be very efficient for matching large datasets. You could take a subsample and do it ‘inefficient’ (maybe even in Excel), to make sure the output is good.

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 06 May 2012 11:27 AM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  5
Joined  2012-05-03

that’s a good idea. I will try!

Yes, the dow-loop is a savior in working with TAQ..

Profile
 
 
Posted: 16 May 2012 01:03 PM   [ Ignore ]   [ # 5 ]
Newbie
Rank
Total Posts:  5
Joined  2012-05-03

If anyone will be interested there should be END_TIMEOKLOOP in both places (the underscore was missing)..


cheers,

Profile
 
 
Posted: 16 May 2012 02:00 PM   [ Ignore ]   [ # 6 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

thanks for the follow-up!

best,

Joost

edit: WRDS has updated the code on the page (END_TIMEOKLOOP and no longer END TIMEOKLOOP), in fact, they have uploaded matched trades-quotes datasets (libname WTAQ ‘/wrds/nyse/sasdata/wrds_taqs_ct’;), see: http://wrds-web.wharton.upenn.edu/wrds/research/applications/intraday/index.cfm

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile