BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TMY
Calcite | Level 5 TMY
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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 */

 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@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

 

 

--
Paige Miller
s_lassen
Meteorite | Level 14

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 */

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 634 views
  • 0 likes
  • 3 in conversation