您的位置:首页 > 其它

读取文件问题

2011-09-23 21:34 162 查看
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\);

还有更多的思路,详见:http://stackoverflow.com/questions/1409543/using-sas-macro-to-pipe-a-list-of-filenames-from-a-windows-directory
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: