如何在UNIX文件夹中检入SAS中的“错误:”的每个日志文件?日志文件在UNIX上

时间:2013-03-20 19:07:02

标签: sas

尝试创建一个日志文件名和对应错误的数据集,其中包含日志文件中的“错误:”。日志文件在UNIX上,我想在SAS上访问该unix路径并搜索“错误:”字符串并创建一个包含日志文件名和错误的数据集。 我不知道如何实现这一点....任何帮助?

提前致谢, 萨姆。

以下是我正在寻找的示例。假设我在UNIX上的/ tcrsk / dev / Logs文件夹下有a.log,b.log,c.log,... n.log文件。为一个程序循环遍历所有日志文件,并创建一个包含2个变量的数据集,如LOg_Name ERROR_Message a.log ERROR:Missing b.log ERROR:No data set c.log ERROR:A lock is not avialable我想这个例子提供了更多细节....

2 个答案:

答案 0 :(得分:3)

在不了解您的文件夹结构的情况下,我无法对问题的第一部分发表评论。一旦知道了日志文件的名称,您就可以使用以下内容。

以下代码创建了2个数据集。第一个是完整的日志,日志中每行一个观察。第二个数据集仅包含已标识为“错误”的那些行。请注意,我将某些警告和注释语句视为错误,因为它们可能会隐藏拼写错误或其他语法或语法问题:

%let logfile = myfile.log;

**
** READ IN LOGFILE. CHECK FOR PROBLEMS
*;

data problems log;
  length line $1000;

  infile "&logfile";
  input;

  logfile = "&logfile";
  line_no = _n_;
  line    = _infile_;
  problem = 0;

  if 
  (
     line =: "ERROR:"
  or line =: "WARNING:"
  or line =: "NOTE: Numeric values have been converted to character values"
  or line =: "NOTE: Character values have been converted to numeric values"
  or line =: "NOTE: Missing values were generated as a result of performing an operation on missing values"
  or line =: "NOTE: MERGE statement has more than one data set with repeats of BY values"
  or line =: "NOTE: Invalid (or missing) arguments to the INTNX function have caused the function to return"
  or line =: "INFO: Character variables have defaulted to a length of 200"
  or line =: "NOTE: Invalid"
  )
  and not
  (
      line =: "WARNING: Your system is scheduled to expire"
  or  line =: "WARNING: The Base Product product with which Session Manager is associated"
  or  line =: "WARNING: will be expiring soon, and is currently in warning mode to indicate"
  or  line =: "WARNING: this upcoming expiration. Please run PROC SETINIT to obtain more"
  or  line =: "WARNING: information on your warning period."
  or  line =: "WARNING: This CREATE TABLE statement recursively references the target table. A consequence"
  or  line =: "WARNING: Unable to copy SASUSER registry to WORK registry. Because of this, you will not see registry customizations during this"
  or  line =: "ERROR: A lock is not available for"
  or  line =: "ERROR: Errors printed on page"
  )
  then do;
    problem = 1;
    output problems;
  end;
  output log;
run;

答案 1 :(得分:0)

/*Creating a dat file with the list of .log files and ERROR: in their body*/    
X 'ls -1 /fbrms01/dev/Logs/*.log | xargs grep -l "ERROR:"  
                                                > /fbrms01/dev/Logs/log_error.dat';
    data log_list; **Accessing dat fil from UNIX and creating dataset on SAS;
    infile '/fbrms01/dev/Logs/log_error.dat' dsd dlm='|' lrecl=1024; 
    input Lname :$75.; 
    run;
    options symbolgen mprint mlogic;
    %macro logfile(DS);
    %let dsid = %sysfunc(open(&DS));
    /*%let obs = %sysfunc(attrn(&dsid,nobs));**To get number of observations in log_list;*/
    Proc datasets;
    Delete  All_Errors;
    %do %while (%sysfunc(fetch(&dsid)) = 0);/*To run the loop thru log_list till the end of obs*/
    %let logfile = %sysfunc(getvarc(&dsid,1));/*To get value */
            data problems ;
                length line $1000 logfile $100;
                infile "&logfile";
                input;
                logfile = "&logfile";
                line_no = _n_;
                line    = _infile_;

                if line =: "ERROR:" then do;
                output problems;
                end;
            run;
            Proc Append Base=All_Errors data=Problems force;
            Run;
        %end;
    %MEND;
    %logfile(log_list);

如果需要任何补充,请告诉我....谢谢,Sam。