I've 5 data steps. If I execute and if there is a WARNING in the first step, I do not want the other steps to execute. Is there a way to achieve this?
The easiest way is to check the SYSCC automatic macro variable. This variables has two advantages:
%let SYSCC=0;
Data x;
/* this is your first data step */
run;
data _null_;
if &syscc then abort cancel file;
run;
I used the CANCEL FILE version of the ABORT statement, as this will not terminate your SAS session if you are testing in oline SAS.
If you only want to exit on errors, you should check for SYSCC>4, 1 to 4 are warnings.
The question should really be, why does the datastep cause errors/warnings? First off, a warning may not fail the following steps, that is a key difference between warning and error. Second, you should be coding "in a defensive manner". What this means is pre-empting and handling issues, if code is throwing errors/warnings later on and your input hasn't changed (as it wont as you will have an import agreement/import process), then the code was not correctly coded first time. Proper testing and robust coding will avoid these issues.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.