SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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