[转载]sas pipe

标签:
转载 |
分类: SAS编程及应用 |
例如:
filename temp pipe "dir F:南昌项目全省气象资料ETO-1981-2012ETO*.txt
/b";
run;
proc print data=name;
run;
此处强调两点:
1、这里现实的是相对路径,如果需要绝对路径,则代码换成:
filename temp pipe "dir F:南昌项目全省气象资料ETO-1981-2012ETO*.txt /b/s";
相关的dos中dir命令见链接:
http://www.360doc.com/content/09/1213/13/5029_11012595.shtml
2、需要在infile后面添加truncover。(不太明白为什么)
二、实现批量导入
(1)利用两个input全部导入,对于命名没规律的文件比写append方法效率高
filename dirpipe pipe “dir
c:Tempcrackman”;/*建立管道,获取文件夹crackman下文件的信息并放在dirpipe中,dirpipe是一个
虚拟的文件,随着pipe的建立而建立,pipe的断开而消失/
data ReadPipe(drop=DateString);
infile dirpipe firstobs=8 truncover;
input DateString
$ 1-10 @;
if DateString=” ” then stop;
input @1
Date : yymmdd10. Time & : time.
Bytes : comma. FileName : $64.;
if Bytes ge 0;
format Date mmddyy10. Time timeampm8. Bytes comma18.;
run;
proc print data=ReadPipe;
title1 “Files identified through unnamed pipe”;
run;
filename dirpipe clear;
(2)、利用宏将文件导入
filename indata pipe "dir d:sasxml /b";
data vname;
length fname $20.;
infile indata truncover;
input fname $20.;
call symput ('nvars',_n_);
run;
%macro want;
%do i=1 %to &nvars.;
data _null_;
set vname;
if _n_=&i;
call symput ('file',fname);
run;
data tmp;
infile "d:sasxml&file." firstobs=2;
input x y z;
run;
proc datasets;
append base=want data=tmp;
quit;
%end;
%mend;
%want
1、这里现实的是相对路径,如果需要绝对路径,则代码换成:
filename temp pipe "dir F:南昌项目全省气象资料ETO-1981-2012ETO*.txt /b/s";
相关的dos中dir命令见链接:
http://www.360doc.com/content/09/1213/13/5029_11012595.shtml
2、需要在infile后面添加truncover。(不太明白为什么)
二、实现批量导入
(1)利用两个input全部导入,对于命名没规律的文件比写append方法效率高
filename dirpipe
虚拟的文件,随着pipe的建立而建立,pipe的断开而消失/
data ReadPipe(drop=DateString);
infile dirpipe firstobs=8 truncover;
input
if DateString=” ” then stop;
input
Bytes : comma. FileName : $64.;
if Bytes ge 0;
format Date mmddyy10. Time timeampm8. Bytes comma18.;
run;
proc print data=ReadPipe;
title1 “Files identified through unnamed pipe”;
run;
filename dirpipe clear;
(2)、利用宏将文件导入
filename indata pipe "dir d:sasxml /b";
data vname;
length fname $20.;
infile indata truncover;
input fname $20.;
call symput ('nvars',_n_);
run;
%macro want;
%do i=1 %to &nvars.;
%end;
%mend;
%want
后一篇:sas/access