%let pwd = %sysfunc(pathname(WORK));
%put pwd=&pwd;
x cd &pwd;
/* test file. more than 10,000 line log file */
data _null_;
file "test.log";
do i = 1 to 1e4;
r = ranuni(0);
put r binary64.;
if r < 0.001 then put "NOTE: not me!";
end;
put "NOTE: find me!";
do until (r<0.1);
r = ranuni(0);
put r binary64.;
end;
stop;
run;
/* find the last line that starts with
NOTE: and get the rest of the line. */
data _null_;
length msg $80;
retain msg;
infile "test.log" lrecl=80 eof=eof truncover;
input head $char5. @;
if head = "NOTE:" then input @6 msg $char80.;
else input;
return;
eof:
put "last note was on line: " _n_ ;
put "and msg was: " msg $80.;
run;
/* on log
last note was on line: 10013
and msg was: find me!
*/
2 回答
如果你的意思是解析sas日志文件,我不确定向后阅读日志文件是否值得在实践中遇到麻烦 . 例如,以下代码在我的PC上执行不到十分之一秒,它正在编写和读取10,000行日志文件 . 您的日志文件有多大,有多少?同样如下所示,您不必在每行上“解析”所有内容 . 您可以有选择地阅读该行的某些部分,如果它不是您想要的,那么您可以转到下一行 .
我可能会设置一个文件名管道语句来使用像
tail -r
或tac
这样的操作系统命令以与SAS相反的顺序显示文件 . 这样SAS可以正常读取文件,您不必担心文件有多长 .