BookmarkSubscribeRSS Feed
11 REPLIES 11
Tom
Super User Tom
Super User

You seem to have forgotten to provide any details to your question.

What log are you trying to read?  it is hard to read the log of the currently running SAS program since it is using it to write to.

You can read the log from a previously run program.

Or use PROC PRINTTO to redirect the log for part of your program and then read that file back in.

 

Personally when looking for error messages from SAS I look for lines that start with the letters ERROR and have a colon. Sometimes SAS puts characters between the R and the colon.

input;
if  _infile_ =: 'ERROR' and index(_infile_,':');
mohanj1
Calcite | Level 5

Sorry for the not providing complete details.

 

There were  lot of logs created on daily basis(example 10 logs each day).

I don't want to open each job log and search for the ERROR.

I want to write a program which will read the each job log from the path  and in case of any ERROR i want display in output.

 

Thanks,

Mohan

SASKiwi
PROC Star

I'm guessing you are running these jobs in batch mode. If so and you use a scheduler to run them, then many schedulers can be configured to send an email if there is a non-zero return code on the job, that is it contains an error.

 

So that means you only need to look at job logs that send an email and hopefully there are so few of these manual checking is OK. This is what we do and it is simple and effective way of job monitoring.

mohanj1
Calcite | Level 5

Hi ,

 

Actually the log contains Xcom information and its taking too much time to open and check the each log. Its time consuming.

 

That's why i want to write a code which will read the logs and gives me output in case of any ERROR.

 

Regards,

Mohan

ScottBass
Rhodochrosite | Level 12

Why does it have to be "...using SAS code"?

 

I've done this all the time using scheduled jobs and post-processing.

 

On *nix I use grep.

On Windows I use Powershell.  Or I install grep on Windows and use it as well (but usually I use Powershell).

 

For Windows, see https://github.com/scottbass/Powershell/blob/master/Scripts/Sas.ps1

 

The Print-SASErrorsOrWarnings function beginning on line 478 prints ERRORS or WARNINGS to the output console.  And the scheduler software I used sent all console output in an email for failed jobs.  The Select-String cmdlet prints one line of context before and after the error message (something that would take a lot of work using SAS to process the log files).

 

Perhaps you can adapt this to meet your needs.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
mohanj1
Calcite | Level 5

Thank you.

 

But the jobs are scheduled in the server we can't connect to the server using the putty.

 

So could you please let me know  sample procedure to write a code to check the ERROR in the log.

 

Regards,

Mohan.

ScottBass
Rhodochrosite | Level 12

But the jobs are scheduled in the server

 

How are the jobs scheduled in the server, i.e. what scheduler do you use?

Do you have access to those jobs, i.e. can you edit the jobs?

Even if you don't have edit access, how are the jobs created?  Do you pass the jobs to an admin person who implements them in the scheduler?

Are the job logs written to a file share that you have access to?

Are you on Windows or *nix?

 

So could you please let me know  sample procedure to write a code to check the ERROR in the log.

 

I already did in my last post.  On Windows, use the Select-String Powershell cmdlet.

 

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
mohanj1
Calcite | Level 5

Thanks.

 

I never used the power shell cmdlet. So coudl you please let me know how to use the power shell cmdlet.

 

Regards,

Mohan.

ScottBass
Rhodochrosite | Level 12

@mohanj1 wrote:

Thanks.

 

I never used the power shell cmdlet. So coudl you please let me know how to use the power shell cmdlet.

 

Regards,

Mohan.


https://www.google.com/search?q=powershell+select-string

 

Also, just to make clear:  when a SAS batch job is running, and writing to its log file, it has an exclusive lock on that file.  So, a SAS job cannot read from the log file that it is creating.  You have to read the log in a post-processing step, after the SAS job has finished.  grep and powershell are good tools for this, and is what I've recommended.  You could launch a 2nd SAS batch job to parse the log file from the first job, but IMO that is overkill, and not even the best tool for the application at hand.

 

"When the only tool in your toolbox is a hammer, everything looks like a nail".

 

I suggest you do a bit of self-study to improve your toolbox.

 

I'm unsubscribing from this one.  Good luck, hope you get it working!


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Kurt_Bremser
Super User

Any "server" that deserves to be called a server MUST have SSH installed and the daemon running. It's THE most versatile communication protocol in use today. Check again, please.


@mohanj1 wrote:

Thank you.

 

But the jobs are scheduled in the server we can't connect to the server using the putty.

 

So could you please let me know  sample procedure to write a code to check the ERROR in the log.

 

Regards,

Mohan.




Kurt_Bremser
Super User

Since your jobs are scheduled, the scheduler will catch non-zero return codes anyway and alert you to SAS ERROR conditions (they cause a return code of 2). You should watch out for any non-zero exit, though.

Then it's just a matter of locating the respective log and reading it.

But @ScottBass is right, the #1 tool for this is grep. Maxim 14.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 2573 views
  • 3 likes
  • 5 in conversation