I wold like to know if there is any way to jump or leave the task (a serie of proc selections) if the result of the following count were zero
Select count(*) as N_registro from WORK.SIMU_DADOS_CLIENTE
where tp_renda= "Month";
if the count of these select were not zero, then they continue the task or the other proc selections in the task/program.
You may want to use the ABORT CANCEL FILE statement:
proc sql noprint;
Select count(*) into :N_registro from WORK.SIMU_DADOS_CLIENTE
where tp_renda= "Month";
quit;
data _NULL_;
if &N_registro=0 then do;
putlog 'No relevant data, processing skipped';
abort cancel file;
end;
run;
I modified the SQL to put the result into a macro variable, which I could then use to test in the datastep.
The ABORT statement does different things depending on the options used. ABORT CANCEL FILE stops processing the current %include file or submit block, without terminating SAS.
So, if you want to use it for jumping to a new section, collect the statements that should be skipped i a distinct SAS program file, and put the test inside that file as well.
You can then use it like
/* preliminary SAS code goes here */
%include 'program1.sas'; /* this is the SAS program that you want to jump out of */
/* continue processing here */
@TMY wrote:
I wold like to know if there is any way to jump or leave the task (a serie of proc selections) if the result of the following count were zero
if the count of these select were not zero, then they continue the task or the other proc selections in the task/program.
This could be done in a macro (or if you have SAS 9.4M5 or later, you don't even need a macro).
Example — note the colon in front of N_registro which creates a macro variable called N_registro
%macro guineapigs;
proc sql;
Select count(*) into :N_registro from WORK.SIMU_DADOS_CLIENTE where tp_renda= "Month";
quit;
%if &n_registro>0 %then %do;
proc whatever;
...
run;
%end;
%mend;
%guineapigs
You may want to use the ABORT CANCEL FILE statement:
proc sql noprint;
Select count(*) into :N_registro from WORK.SIMU_DADOS_CLIENTE
where tp_renda= "Month";
quit;
data _NULL_;
if &N_registro=0 then do;
putlog 'No relevant data, processing skipped';
abort cancel file;
end;
run;
I modified the SQL to put the result into a macro variable, which I could then use to test in the datastep.
The ABORT statement does different things depending on the options used. ABORT CANCEL FILE stops processing the current %include file or submit block, without terminating SAS.
So, if you want to use it for jumping to a new section, collect the statements that should be skipped i a distinct SAS program file, and put the test inside that file as well.
You can then use it like
/* preliminary SAS code goes here */
%include 'program1.sas'; /* this is the SAS program that you want to jump out of */
/* continue processing here */
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.