0
votes

I created a macro using SAS version 9.4 to read data from DTAQ zip dataset. the code looks like the following (it is reading data from DTAQ trade file one day at a time):

libname rasheek "D:\Rasheek I\";

*** Loop for processing DTAQ_2.1 data;
%macro ZipRead_vars(rawzip,rawfile,outdata,outdata1, ddt,round,macrofile);
%do rd=1 %to &round;
%global zipfile mb outdt outdt1 datadate;
%let zipfile=%scan(&rawzip,&rd,'*');
%let mb=%scan(&rawfile,&rd,'*');
%let datadate=%scan(&ddt,&rd,'*');
%let outdt=%scan(&outdata,&rd,'*');
%let outdt1=%scan(&outdata1,&rd,'*');
%scan(&macrofile,1,'#');
%end;
%mend ZipRead_vars;



%ZipRead_vars(D:\DTAQ_RAW\2014\201401\Trd\EQY_US_ALL_TRADE_20140102.zip*
D:\DTAQ_RAW\2014\201401\Trd\EQY_US_ALL_TRADE_20140103.zip*,
taqtrade20140102*taqtrade20140103*,
rasheek.trd_20140102*rasheek.trd_20140103*,
rasheek.trd_20140102_1*rasheek.trd_20140103_1*, 
20140102*20140103*,2,%TRD_Read21;#);

%macro TRD_Read21;
filename trd zip "&zipfile" member="&mb";
Data &outdt;
Infile trd firstobs=2 missover;
input
@1 hh 2.
@3 mm 2.
@5 ss 2.
@7 ss1 3.
@1 time 9.
@10 Exchange $1.
@11 Symbol $16.
@27 SaleCondition $4.
@31 TradeVolume 9.
@40 TradePrice 11.4

    date=&datadate;
    ticker=compress(symbol);
    stime=hh*3600+mm*60+ss+0.001*ss1;
    DollarVolume=TradeVolume*TradePrice;
    if stime<34200 or stime>57600 then delete;
    run;

proc sql;
create table &outdt1 as 
select date, symbol,SaleCondition, sum(tradevolume)as totaltradevolume, sum(dollarvolume)as totaldollarvolume
from &outdt
group by date, symbol, SaleCondition
;
quit;
%mend TRD_Read21;

When I run the code I get error: more positional parameters found than defined. However, if I change the last part of the code to the following it works. 

create table &outdt1 as 
select * from &outdt
;
quit;
%mend TRD_Read21;

please help/guide me in fixing the code. Thank you in advance  

1
Where are you getting the error?Tom
Please DON'T SHOUT at us. This does not make help come faster.Adrian W

1 Answers

2
votes

One thing you can do to avoid the more positional parameters error message is to always call the macro using the parameter names. That way you know which parameter is getting which value in your call. SAS allows you to use the parameter names in the call even for parameters that are defined such that they can also be called by position.

So let's do that for your macro call:

%ZipRead_vars
(rawzip=D:\DTAQ_RAW\2014\201401\Trd\EQY_US_ALL_TRADE_20140102.zip
*D:\DTAQ_RAW\2014\201401\Trd\EQY_US_ALL_TRADE_20140103.zip*
,rawfile=taqtrade20140102*taqtrade20140103*
,outdata=rasheek.trd_20140102*rasheek.trd_20140103*
,outdata1=rasheek.trd_20140102_1*rasheek.trd_20140103_1*
,ddt=20140102*20140103*
,round=2
,macrofile=%TRD_Read21;#
);

The value for that last parameter, MACROFILE, looks strange. You want to put the text generated by the macro %TRD_READ21 as the string to pass into the macro %ZipRead_vars? Does that macro only generate text? If it generates code then the code it generates will be passed as the value of the MACROFILE parameter instead of being executed by SAS.

If you want to pass the NAME of a macro to call then do not include the % in the call.

...,macroname=TRD_READ21,....

Then in your macro definition you can use the name to call the macro.

%let macroname=%scan(&macroname,1,#);
%&macroname;