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

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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