我使用在線發現的宏將多個excel文件導入到單個sas數據集中。它工作得很好。但我也想添加一個變量「板」來指定每個excel文件。下面是宏:在導入後但在追加之前添加變量
%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);
我寫了一個做循環的call execute
裏面,proc import
後運行一個小的數據的一步,但proc append
之前。但它不起作用。任何人都可以有任何想法如何在追加數據集之前添加此變量。 非常感謝您提前。
優秀!非常感謝你!!! – lxcfuji