启用 SAS 代码中多个 PROC SQL 的错误检查

huangapple go评论84阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月24日 01:28:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定