DATA Step, Macro, Functions and more

Stop program execution at a particular row

Reply
Occasional Contributor
Posts: 9

Stop program execution at a particular row

I'm trying to find a way to halt execution at a particular row.   "Abort Abend" will do it, but it also seems to delete all my temprorary files.   Is there a way to stop execution at particular row and keep the temporary files in the work directory?

Super User
Posts: 5,516

Re: Stop program execution at a particular row

In a DATA step, the STOP statement halts the current step.  For example:

 

data want;

set have;

if amount > 5000 then stop;

run;

 

It stops before outputting the current observation.  In this case, the output data set contains zero observations with amount greater than 5000.

Occasional Contributor
Posts: 9

Re: Stop program execution at a particular row

Posted in reply to Astounding

Understood.   However, unless I'm mistaken, the stop statement within a data step would only halt execution for that particular data step.   Subsequent steps would proceed.    I'd like the halt execution of the entire program, so no subsequent steps would run.

Super User
Posts: 5,516

Re: Stop program execution at a particular row

That takes a lot more work.  For example, you could define a macro:

 

%macro runn;

   %global halt;

   run &halt;

%mend runn;

 

Then end every step by replacing the RUN; statement with:

 

%runn

 

Then in your DATA step:

 

if amount > 5000 then call symput('halt', 'cancel');

 

Before this point, the %RUNN macro would generate:

 

run;

 

Afterwards, it generates:

 

run cancel;

 

There's no easy way that I know of.

Ask a Question
Discussion stats
  • 3 replies
  • 78 views
  • 0 likes
  • 2 in conversation