我现在在一个文件夹中批量读入txt文档,代码如下:
%let dirs=C:\Documents and Settings\Administrator\桌面\stock;
%macro get_filenames(location);
filename _dir_ "%bquote(&location.)";
data filenames(keep=memname tmp);
handle=dopen( '_dir_' );
if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
tmp=i;
tmp=Tranwrd(tmp," ","");
memname=dread(handle,i);
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;
%get_filenames(&dirs);
data filename;
set filenames;
name=substr(MEMNAME,1,8);
keep tmp name ;
rename TMP=id NAME=stockid;
label TMP=id NAME=stockid;
run;
data filename;
set filename;
format stocknum $20.;
stocknum="stock"||strip(id);
call symput(stocknum,stockid);
run;
以上是设置宏变量,
%macro recycle;
%do i=1 %to 1000;
proc import out=&&stock&i
datafile="E:\stock\&&stock&i..txt"
dbms=tab replace;
getnames=yes;
run;
%end;
%mend;
%recycle;
以上是批量读入。但是结果报错:ERROR: File Name value exceeds maximum length of 201 characters.
事实上我的文件名没有那么长啊,求解!!!