我正在尝试使用Pipe Command读取包含zip文件的文件夹。但我得到错误说ls命令无法识别。文件夹/ PROD /
中实际上有2个zip文件(ABC _ * .zip)
有人可以帮助我吗?
%let extl_dir=/PROD/ ;
filename zl pipe "ls &extl_dir.ABC_*.zip";
data ziplist_a;
infile zl end=last;
length path $200 zipnm $50 filedt $15;
input path $;
zipnm=scan(path,-1,"/");
filedt=scan(scan(path,-1,"_"),1,".");
call symput('zip'||left(_n_), zipnm);
call symput('path'||left(_n_), path);
call symput('filedt'||left(_n_),filedt);
if last then call symput('num_zip',_n_);
*call symput('flenm',filenm);
run;
答案 0 :(得分:1)
SAS发布了一个方便的宏来列出目录中不依赖于运行外部命令的文件。它可以找到here。我更喜欢这种方法,因为它不会引入可能错误的外部源,例如用户权限,管道权限等。
宏使用datastep函数(通过%sysfunc
),并且可以从datastep以相同的方式调用命令。以下是提取图块信息的示例。
%let dir = /some/folder;
%let fType = csv;
data want (drop = _:);
_rc = filename("dRef", "&dir.");
_id = dopen("dRef");
_n = dnum(_id);
do _i = 1 to _n;
name = dread(_id, _i);
if upcase(scan(name, -1, ".")) = upcase("&fType.") then do;
_rc = filename("fRef", "&dir./" || strip(name));
_fid = fopen("fRef");
size = finfo(_fid, "File Size (bytes)");
dateCreate = finfo(_fid, "Create Time");
dateModify = finfo(_fid, "Last Modified");
_rc = fclose(_fid);
output;
end;
end;
_rc = dclose(_id);
run;