BookmarkSubscribeRSS Feed
shlomiohana
Obsidian | Level 7

Hello,

 

My program is divided so that there is a main program called 000_batch that running all other programs, look like:

 

%let pgm=C:\Users\freet\Desktop\SAS;

%include &pgm.010_batch;

%include &pgm.020_batch;

 

I want to give IF conditions in the program 010_batch that if the condition will met the SAS program will be stopped completely and not continue to 020_batch program.

I would appreciate your assistance

2 REPLIES 2
Reeza
Super User

It depends a bit on your version of SAS but assuming you're 9.4M5+ something like this works:

 

%if insertCondition %then %do;
    %include .....;
%end;

%else %if insertCondition2 %then %do;
    insert other code;
%end;

%else %do;
       insert other code here;
%end;

@shlomiohana wrote:

Hello,

 

My program is divided so that there is a main program called 000_batch that running all other programs, look like:

 

%let pgm=C:\Users\freet\Desktop\SAS;

%include &pgm.010_batch;

%include &pgm.020_batch;

 

I want to give IF conditions in the program 010_batch that if the condition will met the SAS program will be stopped completely and not continue to 020_batch program.

I would appreciate your assistance


 

Shmuel
Garnet | Level 18

Stopping a sas to run depends on what kind of condition is and what exactly you want to stop::

(1) In case the condition is based on input data then use:

     

If <condition> then stop run;

 

or if you want to cancel the batch job,or the sas sesssion you can use:

    

if <condition> then abort [abend] <return code>;

 

Better check the full documentation of ABORT statement.

 

(2) In case condition depends on outer arguments (suppose some macro variable or a return code from a sas step, then use @Reeza 's suggestion or code the macro program as:

%macro <macro_name>(...arguments ...);
       %if <condition> %then ...

      %else %if <condition to exit macro >
                      %then %goto exit;

     .......

%exit:
%mend <macro_name>;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1208 views
  • 0 likes
  • 3 in conversation