热线电话:13121318867

登录
首页精彩阅读SAS日志检测
SAS日志检测
2017-05-12
收藏

SAS日志检测

以前跑数据集市时,通常是每天自己批量跑,如果每天查看日志非常麻烦。今天给大家分享一段数据日志的检测代码,可以判断是是哪天出错了。如下图所示:
[xmy_1487668820/2017-05-05-16-06-49-9355.png]
 程序如下:
%macro check_main_log(dizhi);

data rizhi_shujuji3;

  infile "&dizhi." end=eof length=length;

  input jilu $400. length;

run;

/*将错误的记录找出来,进行排列*/

data xiugai3;

  set rizhi_shujuji3 end=w;

  retain errcount 0;

jilu=left(trim(jilu));

  if jilu=:"ERROR:" or jilu=:"WARNING:" or jilu=:"ERROR" or jilu=:"WARNING" then do;

errcount=errcount+1;

  call symput("errcount",errcount);

  end;

  if w then do;

panduan=errcount;

  end;

run;


data c3;

  set xiugai3;

  if panduan~=.;

  %let panduan=panduan;

  call symput("panduan",panduan);

run;

/*找出错误记录所在的行数*/

data xiugai3;

  set xiugai3;

  retain errfound 0;

  if errcount~='' then errfound=errfound+1;

run;

/*排序记录排列,将错误数据记录保留下来*/

proc sort

  data=xiugai3;

  by errcount;

run;

%if &panduan.=0 %then %do;

data xggg;

  length txtname $400. biaoshi $10. jilu $400.;

  format errcount best12. errfound best12. up_data best12.;

  errcount=0;

  errfound=0;

  up_data=&t.;

  txtname="&dizhi.";

  biaoshi="right";

  jilu="运行无错";

  label jilu='错误记录' errcount='序列' errfound='错误所在行数' txtname="检测文件名称" biaoshi="标识";

  %end;

run;

/*建立一个基础数据集放到逻辑库main*/

data main.warning;

length txtname $400. biaoshi $10. jilu $400.;

format errcount best12. errfound best12. up_data best12.;

  txtname="";

  up_data="";

  biaoshi="";

  jilu="";

  errcount="";

  errfound="";

  run;

/*将错误的记录放到main逻辑库*/

proc append

  base=main.warning data=xggg force;

quit;

%if &panduan.>1 %then %do;

data xggg;

  set xiugai3;

  length txtname $400. biaoshi $10. jilu $400.;

  format errcount best12. errfound best12. up_data best12.;

  by errcount;

  txtname="&dizhi";

  up_data=&t.;

  biaoshi="warning";

  if first.errcount;

  if errcount~=0;

  drop panduan;

  label jilu='错误记录' errcount='序列' errfound='错误所在行数' txtname="检测文件名称" biaoshi="标识";

%end;

run;

/*建立一个基础数据集放到逻辑库main*/

data main.warning;

length txtname $400. biaoshi $10. jilu $400.;

format errcount best12. errfound best12. up_data best12.;

  txtname="";

  up_data="";

  biaoshi="";

  jilu="";

  errcount="";

  errfound="";

  run;

/*讲错误的记录放到main逻辑库*/

proc append

  base=main.warning data=xggg force;

quit;

%mend;

********************以下是调用******************

data time;

  format t $8.;

  t=compress(year(today())*10000+month(today())*100+day(today()));

  call symput('t',t);

run;

/*创建文件夹*/

data _null_;

new = dcreate("&t.","&input.");

new1 = dcreate("结果数据","&input.\&t.");

new2 = dcreate("错误数据集","&input.\&t.");

new3 = dcreate("log","&input.\&t.");

new4 = dcreate("main","&input.\&t.");

run;

%let canshu = &input.\&t.\错误数据集;

%let log = &input.\&t.\log;

%let main = &input.\&t.\main;

/*导出日志*/

DM 'LOG;log; FILE "&log.\main.txt" replace;';

run;

/*清除日志*/

DM 'log; "clear";';

/*创建逻辑库*/

libname canshu "&canshu.";

libname main "&main.";

/*调用检测日志的宏程序*/

%check_main_log(&log.\main.txt);
此程序在批量运行中特别方便,只要查看逻辑库main 里的warning数据集就可知道哪里出错。

数据分析咨询请扫描二维码

最新资讯
更多
客服在线
立即咨询