SAS中文论坛

标题: 请教:如何读入多个文件夹下的所有指定文件? [打印本页]

作者: shiyiming    时间: 2008-4-2 16:57
标题: 请教:如何读入多个文件夹下的所有指定文件?
工作中需要将多个目录(总数不确定)内的ABC.TXT读入到一个数据集,请教应如何获取文件所在目录?
  我尝试用以下代码获取文件所在目录,但是x命令必须手工输入EXIT退出。请问,是否有方法可以运行DOS命令且不需要手工干预,或是别的方法实现该目标?

代码:
    x 'd:\test\abc.txt /s >directory.dir';
    data directory;
    infile 'directory.dir';
    input   xxxxxxxxx;
    run;
作者: shiyiming    时间: 2008-4-7 12:18
标题: Re: 请教:如何读入多个文件夹下的所有指定文件?
你可以 environment variable stores all the paths

eg.
set DIR_PATH = D:\test\abc.txt;C:\temp\abc.txt;

Then,
After called up SAS, get back the environment variable DIR_PATH as macro variable

data _null_;
    path=sysget('DIR_PATH');
    call symput('FILE_PATH',path);
run;

Then marco variable &FILE_PATH stores all paths you needed.
You can just use function SCAN() to get every path delimited by ';'
作者: shiyiming    时间: 2008-4-7 17:50
标题: Re: 请教:如何读入多个文件夹下的所有指定文件?
Add the statement below in your pgm.
options noxwait;
作者: shiyiming    时间: 2008-4-17 19:23
标题: Re: 请教:如何读入多个文件夹下的所有指定文件?
hi

[code:3d1snsqx]filename f_list pipe "dir D:\matlabtestdata\test080413 /b";
data mylist;
infile f_list;
input file :$14.;
put file;
run;

proc print;
run;[/code:3d1snsqx]
作者: shiyiming    时间: 2008-6-3 14:06
标题: Re: 请教:如何读入多个文件夹下的所有指定文件?
options noxwait;
该选项可以替代手工输入EXIT退出.




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2