BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
eagles_dare13
Obsidian | Level 7

I want my SAS program to exit if a certain error condition is met.

So in the program outside any proc, data, macro declarations, I write:

if (&errCount > 1) then abort;

I get:

ERROR 180-322: Statement is not valid or it is used out of proper order.

How to solve it?

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

I had taken from the "I want my SAS program to exit if a certain error condition is met." that this is exactly what the OP wants. However, it's worth keeping in mind that WORK datasets won't be available for further examination.

Tom

View solution in original post

9 REPLIES 9
SASKiwi
PROC Star

The ABORT statement is only available in a DATA step:

data _null_;

  if (&errCount > 1) then abort;

run;

http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#p0hp2evpgqvfsfn...

Alternatively you could use %ABORT but that would need conditional macro logic around it inside a macro:

%macro check_error;

%if  (&errCount > 1) %then %abort;

%mend;

eagles_dare13
Obsidian | Level 7

Thanks. I tried the first option.

data _null_;

  if (&errCount > 1) then abort;

run;

I got this in log:

ERROR: Execution terminated by an ABORT statement at line 34 column 31.

Which is ok, but then the rest of the program went on executing as if nothing had happened.

TomKari
Onyx | Level 15

By gar, you're right!

ABEND has different behaviours in batch and interactive. To get it to stop executing in interactive mode, use ABORT ABEND.

Tom

ChrisHemedinger
Community Manager

It's not a good idea to use ABORT ABEND within EG, as it will close your connection with the SAS Workspace. You'll lose your connection to work data, output, and any remaining log messages.  It's a bit like hanging up the phone in the middle of a conversation.

Perfectly fine to use in a batch job though!

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
TomKari
Onyx | Level 15

I had taken from the "I want my SAS program to exit if a certain error condition is met." that this is exactly what the OP wants. However, it's worth keeping in mind that WORK datasets won't be available for further examination.

Tom

SASKiwi
PROC Star

As an interesting aside I have a SAS program that contains an ABORT ABEND. When run in EG I dont want it to abort - no good hanging up mid-conversation as Chris says!

But when run in batch I do want it to abort. Hence I check the _CLIENTAPP macro variable and if populated assume I'm in EG, if not I am in batch. If anyone knows a better way of checking where the program is running I'd be interested. The old SYSENV option is no longer useful as it has the same value for EG and batch.

Astounding
PROC Star

I find that I'm always using %sysfunc(getoption(sysin)) if only to add it to the title.  It returns the complete path to the program in batch, but returns a dot in any form of interactive use.  As long as I am already retrieving it, that's how I distinguish batch use from interactive.

jakarman
Barite | Level 11

This is structural programming like: Nassi–Shneiderman diagram - Wikipedia, the free encyclopedia

Some rules:

- Avoid "go to's  as leading to spaghetti coding. 

- Error signalling is allowed but nice clean-ups should be done

How to do this in SAS? Look what DI is generating a lot of steps just for checking processes and doing error recognition.
The abort should work but I remember there was a situation SAS failed in a nice clean-up (within macro and SAS/AF) causing a cpu-loop. 

There is not issue with all this when you do your code in block's and every block does a check on the error-settings before getting executed.

With SAS you only are able to solve this by using macro-s. Thinking in this kind of logical blocks reuse, restart are more easy to implement   

---->-- ja karman --<-----
arodriguez
Lapis Lazuli | Level 10

Hello,

If your program is a macro, have you tried with %return? This instrucction stop the current macro. I use this instrucction a lot to control bad usage in macros with a command like that

%if condition %then %return;

Regards

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1810 views
  • 3 likes
  • 7 in conversation