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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

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

 

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