如果您有许多客户文件,那么使用pipe to grep可能是一个代价高昂的操作系统操作,而且在SAS服务器上可能不允许使用(pipe、x、system等)
您可以使用的通配符功能在单个数据步骤中读取所有模式命名文件。
infile
以及
filename=
用于捕获正在读取的活动文件的选项。
Sample:
%let sandbox_path = %sysfunc(pathname(WORK));
* create 99 customer files, each with 20 customers;
data _null_;
length outfile $125;
do index = 1 to 99;
outfile = "&sandbox_path./" || 'cust_' || put(index,z2.) || '.txt';
file huzzah filevar=outfile;
putlog outfile=;
do _n_ = 1 to 20;
custid+1;
put custid=;
put "firstname=Joe" custid;
put "lastname=Schmoe" custid;
put "street=";
put "city=";
put "zip=";
put "----------";
end;
end;
run;
* read all the customer files in the path;
* scan each line for 'landmarks' -- either 'lastname' or 'firstname';
data want;
length from_whence source $128;
infile "&sandbox_path./cust_*.txt" filename=from_whence ;
source = from_whence;
input;
select;
when (index(_infile_,"firstname")) topic="firstname";
when (index(_infile_,"lastname")) topic="lastname";
otherwise;
end;
if not missing(topic);
line_read = _infile_;
run;