<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do i skip a task (proc selection) based on a result ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-skip-a-task-proc-selection-based-on-a-result/m-p/590307#M168922</link>
    <description>&lt;P&gt;You may want to use the ABORT CANCEL FILE statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
Select count(*) into :N_registro from WORK.SIMU_DADOS_CLIENTE
where tp_renda= "Month";
quit;

data _NULL_;
  if &amp;amp;N_registro=0 then do;
    putlog 'No relevant data, processing skipped';
    abort cancel file;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I modified the SQL to put the result into a macro variable, which I could then use to test in the datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use it like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* preliminary SAS code goes here */

%include 'program1.sas'; /* this is the SAS program that you want to jump out of */
/* continue processing here */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Sep 2019 09:53:33 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2019-09-20T09:53:33Z</dc:date>
    <item>
      <title>How do i skip a task (proc selection) based on a result ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-skip-a-task-proc-selection-based-on-a-result/m-p/590038#M168831</link>
      <description>&lt;P&gt;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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Select count(*) as N_registro from WORK.SIMU_DADOS_CLIENTE&lt;BR /&gt;where tp_renda= "Month";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if the count of these select were not zero, then they continue the task or the other proc selections in the task/program.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 14:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-skip-a-task-proc-selection-based-on-a-result/m-p/590038#M168831</guid>
      <dc:creator>TMY</dc:creator>
      <dc:date>2019-09-19T14:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do i skip a task (proc selection) based on a result ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-skip-a-task-proc-selection-based-on-a-result/m-p/590042#M168833</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278790"&gt;@TMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if the count of these select were not zero, then they continue the task or the other proc selections in the task/program.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This could be done in a macro (or if you have SAS 9.4M5 or later, you don't even need a macro).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example — note the colon in front of N_registro which creates a macro variable called N_registro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro guineapigs;
proc sql;
    Select count(*) into :N_registro from WORK.SIMU_DADOS_CLIENTE where tp_renda= "Month";
quit;
%if &amp;amp;n_registro&amp;gt;0 %then %do;
     proc whatever;
         ...
     run;
%end;
%mend;
%guineapigs&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 14:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-skip-a-task-proc-selection-based-on-a-result/m-p/590042#M168833</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-19T14:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do i skip a task (proc selection) based on a result ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-skip-a-task-proc-selection-based-on-a-result/m-p/590307#M168922</link>
      <description>&lt;P&gt;You may want to use the ABORT CANCEL FILE statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
Select count(*) into :N_registro from WORK.SIMU_DADOS_CLIENTE
where tp_renda= "Month";
quit;

data _NULL_;
  if &amp;amp;N_registro=0 then do;
    putlog 'No relevant data, processing skipped';
    abort cancel file;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I modified the SQL to put the result into a macro variable, which I could then use to test in the datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use it like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* preliminary SAS code goes here */

%include 'program1.sas'; /* this is the SAS program that you want to jump out of */
/* continue processing here */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 09:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-skip-a-task-proc-selection-based-on-a-result/m-p/590307#M168922</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-09-20T09:53:33Z</dc:date>
    </item>
  </channel>
</rss>

