0
votes

I am having errors as below.

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &N_GROUP

ERROR: The %TO value of the %DO I loop is invalid.

ERROR: The macro ORDERFLOW will stop executing.

When I tested this on local without remote submitting, it worked. But it doesn't work on WRDS server. I have tried many things to fix this but cannot find out what's wrong.

Here is my code. FYI, this is a pilot code for something bigger.

%macro orderflow(YYYYMMDD=, CUTOFF=) /des = "Create OrderFlow"; 

%syslput YYYYMMDD = &YYYYMMDD;
%syslput CUTOFF = &CUTOFF;

%let wrds = wrds.wharton.upenn.edu 4016;
options comamid=TCP;
signon wrds username=_prompt_;

rsubmit;

/* Enter your WRDS institution name and your WRDS username */
options errors=2;

/* STEP 1: RETRIEVE DAILY TRADE AND QUOTE (DTAQ) FILES */
    libname nbbo '/wrds/nyse/sasdata/taqms/nbbo';
    libname cq '/wrds/nyse/sasdata/taqms/cq';
    libname ct '/wrds/nyse/sasdata/taqms/ct';
    libname mast '/wrds/nyse/sasdata/taqms/mast';

    /* Create StockList each having 100 stocks */
    proc sql noprint;
    select  ceil(count(SYMBOL_ROOT)/&CUTOFF)    into :N_GROUP     
    from  mast.mastm_&YYYYMMDD
    where  LISTED_MARKET in ('A' 'N' 'T' 'Q')   /* AMEX, NYSE, NASDAQ */
    and  TAPE = 'A'                         /* Common stock */     
    ; quit;
    
    %do i=1 %to &N_GROUP;
        %global STOCKLIST&i;
        proc sql noprint;
        select  SYMBOL_ROOT  into :STOCKLIST&i  separated by '" "'
        from  mast.mastm_&YYYYMMDD
        where  LISTED_MARKET in ('A' 'N' 'T' 'Q')   /* AMEX, NYSE, NASDAQ */
        and  TAPE = 'A'                             /* Common stock */
        and  monotonic() between &cutoff*(&i-1)+1 and &cutoff*&i
        ; quit;


    /* Retrieve NBBO data */
    data DailyNBBO;

        /* Enter NBBO file names in YYYYMMDD format for the dates you want */
        set nbbo.nbbom_&YYYYMMDD;

        /* Enter company tickers you want */
        where sym_root in ("&&STOCKLIST&i") and 

        /* Quotes are retrieved prior to market open time to ensure NBBO 
           Quotes are available for beginning of the day trades */
        (("9:00:00.000000000"t) <= time_m <= ("9:30:00.000000000"t));
        format date date9.;
        format time_m part_time trf_time TIME20.9;
    run;

    /* Retrieve Quote data */
    data DailyQuote;

        /* Enter Quote file names in YYYYMMDD format for the same dates */
        set cq.cqm_&YYYYMMDD;

        /* Enter the same company tickers as above */
        where sym_root in ("&&STOCKLIST&i") and 

        /* Quotes are retrieved prior to market open time to ensure NBBO 
           Quotes are available for beginning of the day trades*/
        (("9:00:00.000000000"t) <= time_m <= ("9:30:00.000000000"t));
        format date date9.;
        format time_m part_time trf_time TIME20.9;
    run;

    /* Retrieve Trade data */
    data DailyTrade;

        /* Enter Trade file names in YYYYMMDD format for the same dates */
        set ct.ctm_&YYYYMMDD;

        /* Enter the same company tickers as above */
        where sym_root in ("&&STOCKLIST&i") and 

        /* Retrieve trades during normal market hours */
        (("9:30:00.000000000"t) <= time_m <= ("9:30:00.000000000"t));
        type='T';
        format date date9.;
        format time_m part_time trf_time TIME20.9;
    run;

    /* Download to PC */
    proc download data=DailyNBBO out=taq.DailyNBBO_&&YYYYMMDD&i;     run;
    proc download data=DailyQuote out=taq.DailyQuote_&&YYYYMMDD&i;     run;
    proc download data=DailyTrade out=taq.DailyTrade_&&YYYYMMDD&i;     run;

%end;
%mend orderflow;
%orderflow(YYYYMMDD=20141224,CUTOFF=100);

Any comments appreciated. Thanks.

1
You could add a few of the many things you tried to fix it, so you do not get some duplicate suggestions to try.IncredibleHat
Running locally you connect to the WRDS server via RSUBMIT/SIGNON, but if you're running on the server you don't need those statements do you? I'm not 100% sure of how it's set up. Can you add the options mprint symbolgen mlogic; to your code, submit it and post the full log with the error message.Reeza
Thank you for the advice and also for letting me know the options which I did not know before. Your advice worked as well as Tom's did!Jay

1 Answers

1
votes

This macro is constructed to run on the LOCAL machine since it includes both the SIGNON and RSUBMIT/ENDRSUBMIT blocks.

But you are referencing a macro variable N_GROUP that was created on the remote machine via an SQL INTO clause. I assume that is the reason for the error messages.

Either define the macro to run on the remote machine or use %SYSRPUT to move the macro variable value back to the local machine so you can use it to control the %DO loop.