2013-03-20 71 views
1

試圖在日誌文件中創建包含日誌文件名和對應錯誤的數據集,其中包含'ERROR:' .Log文件位於UNIX上,我想要訪問SAS上的該unix路徑並搜索'ERROR:'字符串並創建一個包含日誌文件名和錯誤的數據集。 我沒有線索如何實現....任何幫助?如何在SAS文件夾中的每個日誌文件中檢查'ERROR:'?日誌文件在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我想這個例子給出了更多的細節....

+0

需要更多信息。 SAS是unix還是windows?你如何正常訪問unix位置? – Joe 2013-03-20 19:10:45

+0

@Joe,是的SAS在UNIX上運行。文件夾結構是/ tcrsk/dev/Logs .. – 2013-03-21 12:54:58

回答

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; 
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); 

讓我知道是否需要任何附加....謝謝,山姆。