PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 10, 2022

[FIXED] How do I search for a word and retrieve the whole sentence is SAS

 November 10, 2022     indexing, proc, sas     No comments   

Issue

I wrote a SAS program that outputs the SAS log to a specific folder via PROC PRINTTO. In addition, I used the INDEX function to search the log file for the string "ERROR:" . In case of an error, the INDEX function (using variable X) will be GT 1, thus activating a macro statement - sending an Email that an error occurred. I wish to find a function that looks for the string "ERROR:" but retrieves the whole sentence.


Solution

Not sure about sentences but it should be easy to capture the full text of the line from the log file.

Note that SAS will write the ERROR in the first column, but the colon is not always in the sixth column, sometimes there is text before that. Just searching for 'ERROR:' in the log will miss some errors and find some lines that are not actually errors, such as SAS code used to generate error messages.

So this code will create a dataset with all of the lines with ERROR messages on them. It will also set the macro variable NERROR to the number of errors found.

data errors ;
  if eof then call symputx('nerror',errno);
  infile mylog truncover end=eof;
  line+1;
  input text $char200. ;
  if text=:'ERROR' and index(text,':') then do;
     errno+1;
     output;
  end;
run;

Note if you want to capture the complete error message when it takes multiple lines it will be harder. You will need to decide which of the following lines are part of the message. Plus there can be page breaks inserted in the middle of multiple line error messages.



Answered By - Tom
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,204,871

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing