Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about Dow-Loop SAS code

Status
Not open for further replies.

Ninop

Technical User
May 5, 2012
2
ES
I am trying to run the following code, which was provided ready made by the WRDS site.

I am pretty new to SAS but I have read some manuals and staff about dow-loop as well. 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 code:

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 = 1 OR lagged_match = 1 OR end_of_quotes_file = 1 ); /*Line 6*/
if symbol>cqsymbol OR (symbol = cqsymbol AND date > cqdate) then
  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 - cqtime; TIMEDIFF = 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'T AND cqtime<='16:00:00'T AND ofr>0 AND (ofr-bid)/bid<= 0.1))
end = end_of_quotes_file ;end;end; END 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 = cqtime; format 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


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

ERROR 202-322: The option or parameter is not recognized and will be ignored.

Code:
34   end = end_of_quotes_file ;end;end; END TIMEOKLOOP: ; end;
                                            ----------      ---
                                            79              161
ERROR 79-322: Expecting a ;.

ERROR 161-185: No matching DO/SELECT statement.

where exactly is the semicolon expected and missed? or where is the mistake. I am mainly confused about this part of the code go to END TIMEOKLOOP;


Thank you in advance for your help. I desperately need this code to work for my thesis.
 
World War III will probably be started with a typo...
Don't know if you figured this out yet but I would say you have an invalid label name
END TIMEOKLOOP:
I would try changing this to END_TIMEOKLOOP every where it's referenced and rerun.


 
NDakota,

Thank you very much! it helped!

p.s. I think we can avoid World War III with the help of kind people (like you) :p


Oh, and by the way I am doing this in SAS, but still tradedir1 is not zero for some cases when Price=Midpoint.. I have run out of ideas of why should that be happening.. What am I doing wrong? Do you have any ideas on that? :)


data ADSK;
set ADSK;
if price < midpoint then tradedir1 = -1;
else if price > midpoint then tradedir1 = 1;
else tradedir1 = 0;
run;
 
This likely is a problem how you compare floating point numbers. Depending on how you generate your numbers on the way to the ADSK table, you could introduce some inaccuracy. Check this:

Code:
401  data _null_;
402    base = 5;
403    divide = 3333333;
404    aTear = base / divide;
405    aBucket = 0;
406    do i=1 to divide;
407      aBucket = aBucket + aTear;
408    end;
409
410    put base= aBucket=;
411
412    if aBucket = base
413      then put 'smiling';
414      else put 'still crying';
415    if abs (aBucket-base) < 1e-9
416      then put 'eps smiling';
417      else put 'eps crying';
418
419  run;

base=5 aBucket=4.9999999998
still crying
eps smiling

An epsilon of 1e-9 should be good enough depending on your data, a greater precision than 1e-12 you'll likely not get anyway (haven't checked documentation). I suggest you change your code to this:

Code:
if abs(price - midpoint) < 1e-9 then
  tradedir1 = 0;
else if price < midpoint then 
  tradedir1 = -1;
else
  tradedir1 = 1;

Hope it does the job.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top