I'm using a macro found online to import multiple excel files into single sas dataset. And it works very well. But I also want to add one variable "plate" to specify each excel file. Here is the macro:
%macro MultImp(dir=,range=,out=,n=);
%let rc=%str(%'dir %")&dir.%str(\%" /A-D/B/ON%');
filename myfiles pipe %unquote(&rc);
data list;
length fname $256.;
infile myfiles truncover;
input myfiles $100.;
fname=quote(upcase(cats("&dir",'\',myfiles)));
out="&out";
drop myfiles;
call execute('
%do i=1 %to &n.;
proc import dbms=xlsx out= _test
datafile= '||fname||' replace ;
range="&range";
run;
data _test;
set _test;
plate=&i;
run;
proc append data=_test base='||out||' force; run;
proc delete data=_test; run;
%end;
');
run;
filename myfiles clear;
%mend;
%MultImp(dir=U:\test,range=summary$.D10:Y200,out=test,n=30);
I wrote a do loop inside of call execute, and run a small data step after proc import, but before proc append. but it doesn't work. Can anyone have any idea how can I add this variable before appending datasets.
Thank you very much in advance.