英文:
Enabling Errorchecking for multiple procsql in sas code
问题
我有SAS代码,在一个宏中有3个proc sql代码按顺序执行。我想启用rc检查,以便如果任何一个proc sql抛出错误,其他代码不应该被执行。请告诉我在SAS代码中实现这个的可能方式。
英文:
I have SAS code, within a macro i have 3 proc sql code which gets executed on sequence. I want to enable rc check, so that any of the proc sql throws an error other code shouldn't get executed. Please let me know the possible way to do it within sas code itslef.
答案1
得分: 2
使用systerr自动宏变量和每个SQL块后的条件性中止。由于第二个SQL块中包含错误,下面的宏不会执行第三个SQL块。
%macro foo;
proc sql;
create table one as
select *
from sashelp.cars;
quit;
%if(&syserr. > 6) %then %abort;
proc sql;
create table two as
select *
from table_does_not_exist;
quit;
%if(&syserr. > 6) %then %abort;
proc sql;
create table three as
select *
from sashelp.class;
quit;
%mend;
%foo;
日志:
NOTE: Table WORK.ONE created, with 428 rows and 15 columns.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
ERROR: File WORK.TABLE_DOES_NOT_EXIST.DATA does not exist.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
ERROR: Execution terminated by an %ABORT statement.
[1]: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1wrevo4roqsnxn1fbd9yezxvv9k.htm
英文:
Use the syserr automatic macro variable and a conditional abort after each sql block. The macro below will not execute the third sql block because the second sql block contains an error.
%macro foo;
proc sql;
create table one as
select *
from sashelp.cars;
quit;
%if(&syserr. > 6) %then %abort;
proc sql;
create table two as
select *
from table_does_not_exist;
quit;
%if(&syserr. > 6) %then %abort;
proc sql;
create table three as
select *
from sashelp.class;
quit;
%mend;
%foo;
Log:
NOTE: Table WORK.ONE created, with 428 rows and 15 columns.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
ERROR: File WORK.TABLE_DOES_NOT_EXIST.DATA does not exist.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
ERROR: Execution terminated by an %ABORT statement.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论