Benjamin
Benjamin

Reputation: 561

Reviewing the output log of SAS code

A member in my team is using SAS and their code returns "Errors", "Invalid", "Merge statements", "Uninitialized" and "Warning" statements when the input files are incorrect for whatever reason.

After running the code, I routinely check the output log for these key words using CTRL+F and have to amend my input files accordingly.

As you can imagine, using CTRL+F is quite laborious.

I would like the code to automatically print at the end of the output if there were any of the above statements earlier in the output.

How can I do this? Where can I find information on how to program this?

I'm using SAS 9.1

Upvotes: 2

Views: 1088

Answers (2)

Joe
Joe

Reputation: 63424

If you upgrade to SAS 9.4 and use Enterprise Guide for your programming environment, it has an automatic log parser built in that flags errors/warnings, groups them at the bottom, lets you click to find the code or log where they occur, and gives you counts.

Secondly, if you run your code in batch (right click on .sas file -> submit in batch, or run through a .bat file, or similar) then the log will contain pointers to errors at the end, something like "ERRORS WERE PRINTED ON PAGE 45,46,48,55,56". Not warnings or notes, just errors.

Finally, many people have written and published online log parsers/analyzers/readers. Some of those do a similar task to what you request above. SasCommunity has a good list of them, or use the search engine of your choice.

Upvotes: 3

mjsqu
mjsqu

Reputation: 5417

Consider redirecting your log to a file using PROC PRINTTO. From there run this code to find any occurrences of the strings you mentioned:

filename logfl "<insert log filename here>" lrecl=32767;
/* Lrecl set high to ensure long lines are captured */

data _NULL_;
  infile logfl;
  input;
  if index (_infile_,'ERROR:') then put _infile_;
  else if index(_infile_,'WARNING') then put _infile_;
  else if index(_infile_,'uninitialized') then put _infile_;
  else if index(_infile_,'Merge statements') then put _infile_;
run;

Be sure to match the capitalisation of the strings you're looking for, or simply use UPCASE() to bring back any capitalisation, e.g.

if index(upcase(_infile_),'UNINITI') then put _infile_;

Which would match Uniniti, UNINiTi etc.

The code will simply print back the lines of interest in the order found in the log. You could further improve the code by:

  • Putting the strings into a separate dataset or flatfile (in case you find more things you'd like to look for and want to make the code easier to maintain)
  • Print the line number where the string was found (output _N_ along with _infile_ - test this first, I'm not sure if _N_ would map exactly to the line number)

Upvotes: 4

Related Questions