10-03-2017 08:28 AM
Hello, I am trying to stop processing a SAS program (SAS 9.4) when a certain condition is met. here is my code so far. Basically if the count is higher than 0 I would like the program to stop processing immediately and a message to pop up. If the counts are 0, I would like it to continue processing the following code. Thank you
select count(*) into :nb_counts
%if &when ne 0 %then %do;
dm 'post "The ZH_Payments table is done"';
10-03-2017 09:01 AM
Afraid this is typical wrong way around thinking. Doing something unecessary, and then mashing some macro code in to cover up.
In the SASHELP.VTABLE dataset (well view), there is a list of all datasets found in all libraries in the SAS system. This dataset also contains the observation count for each one. Hence the need to open and count each dataset is irrelevant. To get a list of datasets with data you can simply do:
data want; set sashelp.vtable (where=(libname="ABC" and nobs=0)); run;
For more precise code, post example test data in the form of a datastep and require output.
10-03-2017 10:30 AM
It depends a lot on how you are submitting the program to run. If you are running the program directly from the file using the command line or batch submission process then you could just use the ABORT statement to kill the process.
But that will not work very well when submitting a block of code from the program editor in SAS Display Manager or when basically rsubmitting the code to a server process when using SAS EG or SAS/Studio user interface. In those environments you would need to code your whole process to handle the possibility of skipping steps.
What we used to use when we used Display Manager a lot was to have a macro that could test a condition and then conditionally run a %DISPLAY command. That way the process would stop and the user could hit the break key to stop the submitted code. Something like this.
%window ERRORS columns=65 rows=12 icolumn=5 irow=10 #1 "&msg1 " #2 "&msg2 " #3 "&msg3 " #4 "&msg4 " #5 "&msg5 " #7 "Press ENTER to close this window." ; %display errors bell delete;
10-04-2017 03:35 AM
You could use the %ABORT CANCEL FILE statement to stop processing the statements submitted:
proc sql; select count(*) into :nb_counts from new_fee_check; quit; %macro zzz(when); %if &when ne 0 %then %do; dm 'post "The ZH_Payments table is done"'; %abort cancel file; %end; %mend; %zzz(&nb_counts);
It would then stop processing the current program submitted - you will get an error message in the log, though:
8 %macro zzz(when); 9 %if &when ne 0 %then %do; 10 dm 'post "The ZH_Payments table is done"'; 11 %abort cancel file; 12 %end; 13 %mend; 14 %zzz(3); ERROR: Execution canceled by an %ABORT CANCEL FILE statement. NOTE: The SAS System stopped processing due to receiving a CANCEL request.
but you will not have your session killed if you are running SAS EG or Display Manager.