tianwild在其日志中做过详细的记录,题为《读取文件夹下所有相同文件》,链接为
http://www.mysas.net/sns/index.php?app=blog&mod=Index&act=show&id=1834&mid=43
恰巧,mysas论坛上有一问,不同之处,题为:如何读取目录下的所有文件夹名。goole到了结果,想到日后或许用到特此记录:
1. filename pipe
%macro filenames(location); %*--End the %macro
statement
with a semi-colon--*;
filename dirname pipe "dir ""%unquote(&location)"" /b" lrecl=32767;
%*--Surround the macro variable resolution with doubled-up double quotes and %unquote
--*;
data filenames;
infile dirname truncover;
input filename $char1000.;
put filename=;
run;
filename dirname clear; %*--Release the file handle by clearing it--*;
%mend;
%filenames(d:\);
%get_filenames(d:\your dir) %*--Don't single quote your input parameter. macro quote instead, if necessary--*;
2.filename dopen dnum dread
%macro get_filenames(location);
filename _dir_ "%bquote(&location.)";
data filenames(keep=memname);
handle=dopen( '_dir_' );
if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
memname=dread(handle,i);
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;
%get_filenames(C:\temp\);