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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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