So I would like a macro that upon finding the first error when running a project to stop all processes downstream and immediately print an external log. So far I have used the macro that looks like this
%macro check_for_errors; %if &syserr > 0 %then %do; endsas; %end; %mend check_for_errors; data test1; <data step code> run; %check_for_errors;
Currently it will continue with further process the downstream items and include that in the external log. I would like it to after it encounters that first error to stop it and have that error be the last thing it prints to the external log to make debugging easier.
Note: I also have in the project property settings to stop all items on errors during execution.
If you are only running SAS code, then it would be a whole lot easier to run the program in batch mode with the ERRORABEND option set (Add options errorabend; as the first statement in the rpiogram). No checking for errors is required and a SAS log is produced and the program will stop running when the first error is encountered.
I'm confused, I would think ENDSAS would end the session immediately and get what you want.
Can you share the log you get when there is an error?
You might also want to look into the ABORT statement as an alternative to ENDSAS.
If you are only running SAS code, then it would be a whole lot easier to run the program in batch mode with the ERRORABEND option set (Add options errorabend; as the first statement in the rpiogram). No checking for errors is required and a SAS log is produced and the program will stop running when the first error is encountered.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.