有没有办法检测SAS datastep期间是否对缺失值执行了操作?我看了所有automatic macro variables,但似乎没有人做我需要的。我不认为我可以设置SAS代码检查的严格性,以便NOTE: Missing values were generated...
消息成为错误(可能会给&syscc
一些值。)
示例代码:
data _null_;
foo=1;
bar=2;
baz=foo*bar;
put foo= bar= baz= "syscc=&syscc syserr=&syserr";
foo=.;
bar=2;
baz=foo*bar; /*<-- at this point the note about missing values is generated */
/* Here I'd like to be able to do something like; */
/* if [SOME CONDITION] then do;
/* put "operation on missing values occured!" _ALL_;
/* [DO SOMETHING];
/* end; */
put foo= bar= baz= "syscc=&syscc syserr=&syserr";
foo=2;
bar=3;
baz=foo*bar;
put foo= bar= baz= "syscc=&syscc syserr=&syserr";
run;
日志输出(没有来源):
FOO=1 BAR=2 BAZ=2 syscc=0 syserr=0
FOO=. BAR=2 BAZ=. syscc=0 syserr=0
FOO=2 BAR=3 BAZ=6 syscc=0 syserr=0
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 8:8
NOTE: DATA statement used (Total process time):
日志输出我想看:
FOO=1 BAR=2 BAZ=2 syscc=0 syserr=0
operation on missing values occured! FOO=. BAR=2 BAZ=. _ERROR_=0 _N_=1
FOO=. BAR=2 BAZ=. syscc=0 syserr=0
FOO=2 BAR=3 BAZ=6 syscc=0 syserr=0
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 8:8
NOTE: DATA statement used (Total process time):
我正在寻找这个(而不仅仅是检查单个变量的值)的原因是我从一个连续通过套接字收集数据的datastep中得到关于缺失值的很少的注释(可能是从10000行读取的数据)套接字触发缺失值注释)并且在datastep中有几百个数值变量隐藏在三层宏的深处,我正在尝试调试它。
[编辑]
Jeff和Joe建议的note2err
dsoption
做了一些事情,但有点太苛刻了。它只是在生成缺失值消息时立即停止执行,而日志中没有任何更多有用的注释。现在日志是:
FOO=1 BAR=2 BAZ=2 syscc=0 syserr=0
ERROR: Operation performed on missing value at line 8 column 9.
ERROR: Termination due to Missing Value
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
这实际上没有用(虽然如果我启用它会大大增加解决问题的需要)。设置option noerrorabend
不会改变此行为。
答案 0 :(得分:1)
如果我理解你的问题,你可以试试这个:
data _null_;
foo=1;
bar=2;
baz=foo*bar;
put foo= bar= baz= "syscc=&syscc syserr=&syserr";
foo=.;
bar=2;
baz=foo*bar;
if missing(foo) or missing(bar) then put "operation on missing values occured!" _all_;
else put "operation is Ok!";
put foo= bar= baz= "syscc=&syscc syserr=&syserr";
foo=2;
bar=3;
baz=foo*bar;
put foo= bar= baz= "syscc=&syscc syserr=&syserr";
run;