<?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 Abort Data Step when empty file encountered and send &amp;quot;255&amp;quot; code to JES in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Abort-Data-Step-when-empty-file-encountered-and-send-quot-255/m-p/953447#M372490</link>
    <description>&lt;P&gt;I'm trying to send RC=255 to JES when all 3 files are empty. The program sends RC=0 to JES.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET OT.XXXX OT.YYYY OT.ZZZZ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF _N_ = 0 THEN ABORT 255;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks! Les&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2024 19:39:36 GMT</pubDate>
    <dc:creator>LesLim58</dc:creator>
    <dc:date>2024-12-12T19:39:36Z</dc:date>
    <item>
      <title>Abort Data Step when empty file encountered and send "255" code to JES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Abort-Data-Step-when-empty-file-encountered-and-send-quot-255/m-p/953447#M372490</link>
      <description>&lt;P&gt;I'm trying to send RC=255 to JES when all 3 files are empty. The program sends RC=0 to JES.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET OT.XXXX OT.YYYY OT.ZZZZ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF _N_ = 0 THEN ABORT 255;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks! Les&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 19:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Abort-Data-Step-when-empty-file-encountered-and-send-quot-255/m-p/953447#M372490</guid>
      <dc:creator>LesLim58</dc:creator>
      <dc:date>2024-12-12T19:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Data Step when empty file encountered and send "255" code to JES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Abort-Data-Step-when-empty-file-encountered-and-send-quot-255/m-p/953449#M372491</link>
      <description>&lt;P&gt;I would try (untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
  IF _N_ = 1 and last THEN ABORT 255;
  SET OT.XXXX OT.YYYY OT.ZZZZ end=last;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When the step compiles, it will set the variable last to 1 if all datasets on the SET statement have 0 obs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: _N_ is not a counter of the number of records, it's a counter of the number of DATA step iterations.&amp;nbsp; _N_ can never be 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need the PUT statement before the SET statement, because the step will stop when the SET statement executes if there are 0 records to read.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 19:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Abort-Data-Step-when-empty-file-encountered-and-send-quot-255/m-p/953449#M372491</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-12-12T19:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Abort Data Step when empty file encountered and send "255" code to JES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Abort-Data-Step-when-empty-file-encountered-and-send-quot-255/m-p/953479#M372496</link>
      <description>&lt;P&gt;Pretend you are SAS and you have to run your data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
  SET OT.XXXX OT.YYYY OT.ZZZZ;
  IF _N_ = 0 THEN ABORT 255;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;First instruction you get to is the SET statement. When there are zero observations in all three of those input datasets what do you think SAS is going to do in that case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try adding some PUT statements to see what is happening.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
  put 'BEFORE SET STATEMENT. ' _n_= ;
  SET OT.XXXX OT.YYYY OT.ZZZZ;
  put 'AFTER SET STATEMENT.' _n_=;
  IF _N_ = 0 THEN ABORT 255;
  put 'AFTER IF STATEMENT. ' _n_=;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to use a data step to detect number of observations then you need to use either END= or NOBS= options of the SET statement to specify the name of the temporary variable to use for that information.&amp;nbsp; You can then test that variable's value BEFORE the SET statement stops the data step.&lt;/P&gt;
&lt;P&gt;You could use the boolean flag created by the END= option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
  IF EOF THEN ABORT 255;
  STOP;
  SET OT.XXXX OT.YYYY OT.ZZZZ END=EOF;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or the integer value created by the NOBS= option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
  IF NOBS=0 THEN ABORT 255;
  STOP;
  SET OT.XXXX OT.YYYY OT.ZZZZ NOBS=NOBS;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 00:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Abort-Data-Step-when-empty-file-encountered-and-send-quot-255/m-p/953479#M372496</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-13T00:44:09Z</dc:date>
    </item>
  </channel>
</rss>

