Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS trigger error in SAS program executed from SAS-EG

Tags:

sas

I need to get SAS to trigger an error if a certain condition is not meet i have tried to use abort return n, abort abend etc.. but they all seems to to disconnect the entire session where i only want to get an error like with syntax etc.

It is a sas propgram only to be run from SAS-EG in interactive mode with prompts

my code:

DATA _NULL_;
IF prxmatch("/^TBDLZL\d{4}_[A-Z]/",&tablename_in) eq 0 then do;
    put "error table name &tablename_in does not match";
    ABORT RETURN 15; 
END;

RUN;

any suggestions ?

like image 667
havmaage Avatar asked Aug 22 '19 11:08

havmaage


1 Answers

Use the ABORT CANCEL statement. The data step will stop running and the following steps in the submitted code will not be processed.

For example:

data _null_;
  set sashelp.class;
  if name = "John" then do;
    put 'ERR' 'OR: My error message';
    abort cancel;
  end;
run;

* This step is not done due to earlier ABORT CANCEL;
data _null_;
  set sashelp.class;
  where name like 'J%';
run;

From Help:

CANCEL
causes the execution of the submitted statements to be canceled. Actions depend on the method of operation.

  • batch mode and noninteractive mode

    • terminates the entire SAS program and SAS system.
    • writes an error message to the SAS log.
  • windowing environment and interactive line mode

    • clears only the current submitted program.
    • does not affect other subsequent submitted programs.
    • writes an error to the SAS log.
  • workspace server and stored process server

    • clears only the currently submitted program.
    • does not affect other subsequent submit calls.
    • writes an error message to the SAS log.
  • SAS IntrNet application server

    • creates a separate execution for each request and submits the request code. A CANCEL argument in the request code clears the current submitted code but does not terminate the execution or the SAS session.
like image 191
Richard Avatar answered Oct 22 '22 17:10

Richard