BookmarkSubscribeRSS Feed
Ullsokk
Pyrite | Level 9

I have a batch job that reads which programs to run from an excel file. However, sometimes one of the programs gets errors, which seems to cause the entire macro loop to end. How can I get the program to simply skip to the next iteration instead?

 

After importing the file into a dataset batch, the program selects the rows flagged for running, and runs them in a loop.

 

data batch;
set batch;
where run_flg = 1;
row= _n_;
run;

proc sql noprint;
select max(row) into: stop from batch;
quit;

%macro batch;
%local i;
   %do i = 1 %to &stop. ;

proc sql noprint;
select path into: pgm from batch where row = &i.;
quit; 
%include &pgm.;
  
%end;
%mend batch;

%batch;

I want the program to end the loop if an error occors, but proceed to the next interation and the next program, so that one buggy program doesnt stop the next from running

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Depends very much on the bug.  If it is something that will spill over into other code - mismatched quotes are one example - then not in one session can you do such a thing.  You could theoretically open a new session for each program run, using command line etc. but why?  Why is the code your running throwing problems - far better to have robust code which doesn't fall over all the time than to try to avoid it, possibly causing further unexpected issues down the line.  

ballardw
Super User

@Ullsokk wrote:

I have a batch job that reads which programs to run from an excel file.

 

After importing the file into a dataset batch, the program selects the rows flagged for running, and runs them in a loop.


If you scan this forum for issues related to importing data from Excel you might want to consider that either how you flag them or the actual contents have issues when you modify the Excel and re-import it.

Recurring themes: The length of the variable that holds the program name changes from execution to execution: You don't say how your read the Excel file, if using proc import this problem is very likely going to recur as the procedure has to guess how long the variable should be and if bottom rows are longer than then top very likely to have the names truncated.

 

What KIND of errors are you getting will likely have some impact. If the individual programs are failing because of a dependency such as a missing data set or one with that exists but has not observations then each of those programs should have logic to check and not execute when the dependent items aren't available.

If they are failing because of syntax errors then the code for that program does not belong in batch job at all and beat the writer with wet spaghetti noodles until fixed.

 

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