简体   繁体   English

如何搜索一个单词并检索整个句子是 SAS

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

I wrote a SAS program that outputs the SAS log to a specific folder via PROC PRINTTO.我编写了一个 SAS 程序,该程序通过 PROC PRINTTO 将 SAS 日志输出到特定文件夹。 In addition, I used the INDEX function to search the log file for the string "ERROR:".此外,我使用 INDEX function 在日志文件中搜索字符串“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.如果发生错误,INDEX function(使用变量 X)将为 GT 1,从而激活宏语句 - 发送发生错误的 Email。 I wish to find a function that looks for the string "ERROR:" but retrieves the whole sentence.我希望找到一个 function 来查找字符串“ERROR:”但检索整个句子。

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.注意SAS会在第一列写ERROR,但冒号并不总是在第六列,有时前面还有文字。 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.只是在日志中搜索'ERROR:'会漏掉一些错误,并找到一些实际上不是错误的行,例如用于生成错误消息的SAS代码。

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.它还将宏变量 NERROR 设置为找到的错误数。

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.另外,可以在多行错误消息的中间插入分页符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM