BookmarkSubscribeRSS Feed
Hedegaard
Calcite | Level 5

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.

3 REPLIES 3
Hedegaard
Calcite | Level 5

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.

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1058 views
  • 0 likes
  • 3 in conversation