Pane
Pane

Reputation: 555

Stop SAS execution

Quick question

Is there a one-liner (or something rather short) method of cancelling the execution of further SAS statements from withing the windowing environement.

These are the methods I know of but they get tiresome, espeacially in huge programs with a lot of comments. I tried the ABORT and STOP statements but they close the windowing enviroment yet all I want is to stop execution at a certain point and go on my merry way.

Thanks

Upvotes: 10

Views: 20466

Answers (4)

access_granted
access_granted

Reputation: 1927

this worked for me

endsas;

while abort cancel statements gave me exit code 2, which is not always useful when debugging

Upvotes: 0

David Bassein
David Bassein

Reputation: 11

i've been searching for this too - documentation is not good on this one. Trial and error (sigh...). This, amazingly, undocumented feature worked for me:

data _null_ ;
  ABORT CANCEL ;
run ;

Pretty simple! Nothing after that executed, and yet the SAS application remained open.

Upvotes: 1

Jeremy Bassett
Jeremy Bassett

Reputation: 171

I have used the following

%abort cancel;

Upvotes: 1

Joe
Joe

Reputation: 63434

This is something that comes up on SAS-L every so often. The answer is that it depends on what you're doing, largely.

The run cancel method is probably best if you are hoping to stop execution because of an error. At the top of your program you do:

%let cancel =; *or any macro variable name, but cancel is most logical;

Then in every run step you have:

data whatever;
... do stuff ...;
run &cancel;

And each time you have some potential error, you check the error condition and then if it hits,%let cancel=cancel; and you're good.

If you are using macros, you can exit a macro smoothly with %abort as long as you either use no options or only use cancel. Depending on what you're doing, you might set up your code to run in a macro (or macros) and use this option (although with the disadvantage of losing some log clarity).

Finally, if you're just interesting in being able to run a subset of your code, I recommend writing the code in multiple SAS programs for the bits you might want to run separately, then using %include from a master program to group them all together along with any macro variables you might want set that are shared. This is similar to how in EG you would construct many smaller programs and then group them using the process flow diagram.

Upvotes: 6

Related Questions