DATA Step, Macro, Functions and more

How can I check this in a file

Reply
Contributor
Posts: 40

How can I check this in a file

hi,

  I need to check multiple log files if they are created today and to check if no error exists in log files without manually opening log files. Can this be done using SAS statements ?

thanks,

basesas


Respected Advisor
Posts: 4,925

Re: How can I check this in a file

Are those log files from SAS?

PG
Contributor
Posts: 40

Re: How can I check this in a file

Yes...SAS logs

Respected Advisor
Posts: 4,925

Re: How can I check this in a file

Assuming your log file all sit in the same directory under Windows, you could do :

%let logPath=YOUR_LOG_PATH;

filename toto PIPE "DIR ""&logPath.\*.log"" /n/o-d/t:c " console=min;

data test(keep=logFile);
retain todayStr;
length logFile $200;
infile toto;
if _n_ = 1 then todayStr = put(today(),yymmddd10.);
input;
if substrn(_infile_,1,10)=todayStr then do;
logFile = substrn(_infile_,37);
output;
end;
run;

filename toto dummy;
data _null_;
set test;
logPath = cats("&logPath.\", logFile);
do until (_eof);
infile toto filevar=logPath end=_eof;
input;
if substrn(_infile_,1,6) = "ERROR:" then do;
  put "Error found in log file: " logFile " : " _infile_;
  _eof =  1;
    end;
end;
run;

not fully tested... Not likely to work on UNIX - PG

PG
Super User
Posts: 10,028

Re: How can I check this in a file

Here is the code I wrote before.

data _null_;
 infile '/spds_data6/temp/jh.txt' dlm=' ' length=len expandtabs;
 input row $varying200. len;
 if left(row) in: ('ERROR' 'WARNING') then put row;run;

Ksharp

Respected Advisor
Posts: 4,925

Re: How can I check this in a file

Thanks Ksharp for the colon modifier. I learned something. - PG

PG
Ask a Question
Discussion stats
  • 5 replies
  • 300 views
  • 1 like
  • 3 in conversation