DATA Step, Macro, Functions and more

Stop submitted statements without errors in the log

Reply
Contributor
Posts: 24

Stop submitted statements without errors in the log

Hello,

I have a program that I run with a variety of parameters. For certain choices of parameters, I want a condition in the beginning of my program that says that the program should stop executing immediately, thus not completing all the following data steps and macro functions, but without printing an error message to the log.

The abort statement works, but it prints an error message to the log.

So I would like something in the lines of:

%macro stopProgram;

%if &parameter. = 1 %then %do;

     <command that stops the program from running, but doesn't print an error>

%end;

%mend;

%stopProgram;

<rest of huge program>

I would like to avoid having to wrap the entirety of the rest of the program in a large macro. Any ideas are appeciated.

Kind regards,

Rasmus Hedegaard.

Respected Advisor
Posts: 3,799

Re: Stop submitted statements without errors in the log

Posted in reply to Hedegaard

endsas;

Contributor
Posts: 24

Re: Stop submitted statements without errors in the log

Posted in reply to data_null__

Thanks, I have also had a look at endsas;.

It prints no error message to the log, but it closes SAS entirely. I am hoping for something that stops the program, but leaves SAS open.

Super User
Posts: 11,343

Re: Stop submitted statements without errors in the log

Posted in reply to Hedegaard

You may want a %goto statement that branches to a place in your macro that has no code executing afterwards. That may require a macro to surrround all of your existing code for the logic to work.

Something like:

%macro control(<parameters needed>);

<start of code>

/*at problem location*/

%if &parameter = 1 %then %goto endit;

<code you don't want to run>

%endit: %mend control; /* NOTE the full colon is used for the target label*/

Or use

%if &parameter = 1 %then %do;

     %put NOTE: Program terminated because parameter &parameter was 1;

     %goto endit;

%end;

to provide a graceful message in the log about the termination.

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