如果您的意思是解析一個sas日誌文件,我不確定是否向後讀取日誌文件在實踐中是值得的。例如,下面的代碼在我的PC上執行時間不到十分之一秒,它正在寫入和讀取10,000行日誌文件。你的日誌文件有多大?有多少?同樣如下所示,您不必「解析」每一行上的所有內容。你可以有選擇地閱讀該行的一些部分,如果它不是你正在尋找的東西,那麼你可以去下一行。
%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!
*/