<?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: Is there a way to exit a Proc FCMP SUBROUTINE early ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958471#M374070</link>
    <description>&lt;P&gt;The LEAVE statement was not appropriate for my situation.&amp;nbsp; However, the old standby GOTO works.&amp;nbsp; I hadn't seen GOTO listed in the FCMP reference, but the docs state:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H2 id="n0vkb7m814c16en1x8yzrktspks1" class="xisDoc-title" tabindex="-1"&gt;Writing Program Statements&lt;/H2&gt;
&lt;P class="xisDoc-paragraph"&gt;The program-statements section of the program is a series of DATA step and or FCMP statements that describe the work to be done by the function or CALL routine. &lt;STRONG&gt;Most&lt;/STRONG&gt; DATA step statements and functions are accessible from PROC FCMP routines.&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;...&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P class="xisDoc-paragraph"&gt;Good advice to check and close all resource handles that might have been opened.&amp;nbsp;&amp;nbsp;&lt;EM&gt;Resource handles obtained in FCMP user functions or subroutines can be passed back to the caller as part of a legitimate coding/framework architecture, so are not auto freed.&lt;/EM&gt;&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;My DATA Step habit is to let the step do it's auto close and deletion of open resources.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Feb 2025 22:48:45 GMT</pubDate>
    <dc:creator>RichardAD</dc:creator>
    <dc:date>2025-02-05T22:48:45Z</dc:date>
    <item>
      <title>Is there a way to exit a Proc FCMP SUBROUTINE early ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958313#M374035</link>
      <description>&lt;P&gt;I have a SUBROUTINE with arguments that get validated.&amp;nbsp; If the validation fails I would like to exit the subroutine instead of having deeply nested if/then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;subroutine xyzzy(file1 $, file2 $, rc, message $)
  outargs result, message;

  if missing (file1) then do ;
    message = 'Argument 1 can not be blank.' ;&lt;BR /&gt;    rc = -1 ;
    &amp;lt;EXIT_STATEMENT&amp;gt; ;&lt;BR /&gt;  end ;
...&lt;BR /&gt;  endsub ;
quit ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Don't really want to have to code.&amp;nbsp; Exit statements such as QUIT; RETURN; EXIT; don't work. Either wrong context for the statement, or invalid compilation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;subroutine xyzzy(file1 $, file2 $, rc, message $)
  outargs rc, message;
  rc = 0 ;
  if not &amp;lt;validation-1-criteria&amp;gt; then do ;
    message = "&amp;lt;validation-1-fail-message&amp;gt;" ;
    rc = -1 ;
  end ;&lt;BR /&gt;  if rc = 0 and not &amp;lt;validation-2-criteria&amp;gt; then do ;
    message = "&amp;lt;validation-2-fail-message&amp;gt;" ;
    rc = -1 ;
  end ;&lt;BR /&gt;...&lt;BR /&gt;  endsub ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Things can go gnarly nested if's because there will be multiple dynamic fileref assignments, fopens, etc...&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 04:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958313#M374035</guid>
      <dc:creator>RichardAD</dc:creator>
      <dc:date>2025-02-05T04:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to exit a Proc FCMP SUBROUTINE early ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958357#M374052</link>
      <description>&lt;P&gt;You can use the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/default/lestmtsref/n03wnjww9jjpm8n1q16exvgtoae9.htm" target="_self"&gt;LEAVE&lt;/A&gt; statement to exit a DO loop or SELECT group prematurely based on a condition. If you are using LIBNAME, FILENAME, DOPEN, FOPEN, or other functions that can lock resources, you might consider instead using a &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/default/lestmtsref/p04lue2yzjvc8xn1603l5kqlw62d.htm" target="_self"&gt;GOTO&lt;/A&gt;&amp;nbsp;statement to jump to an exit routine that includes the appropriate DCLOSE, FCLOSE, FILENAME or LIBNAME functions to release the lock on the files for a graceful exit from the subroutine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 13:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958357#M374052</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2025-02-05T13:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to exit a Proc FCMP SUBROUTINE early ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958401#M374062</link>
      <description>&lt;P&gt;There are probably ways, but perhaps for parameter validation is not needed, or wanted.&lt;/P&gt;
&lt;P&gt;You should validate ALL of the inputs and report ALL of the issues detected and then exit so that the user does not end up fixing the problem with the first parameter only to have the call fail again because the second parameter also had a problem but you didn't tell them.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=0;
if missing (file1) then do ;
  message = 'Argument 1 can not be blank.' ;
  rc = -1 ;
end ;
if missing(file2) then do;
  message = catx(';',message,'Argument 2 cannot by blank.'); 
  rc=-1;
end;
if rc=0 then do;
  ... body of function ...
end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Feb 2025 16:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958401#M374062</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-05T16:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to exit a Proc FCMP SUBROUTINE early ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958471#M374070</link>
      <description>&lt;P&gt;The LEAVE statement was not appropriate for my situation.&amp;nbsp; However, the old standby GOTO works.&amp;nbsp; I hadn't seen GOTO listed in the FCMP reference, but the docs state:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H2 id="n0vkb7m814c16en1x8yzrktspks1" class="xisDoc-title" tabindex="-1"&gt;Writing Program Statements&lt;/H2&gt;
&lt;P class="xisDoc-paragraph"&gt;The program-statements section of the program is a series of DATA step and or FCMP statements that describe the work to be done by the function or CALL routine. &lt;STRONG&gt;Most&lt;/STRONG&gt; DATA step statements and functions are accessible from PROC FCMP routines.&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;...&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P class="xisDoc-paragraph"&gt;Good advice to check and close all resource handles that might have been opened.&amp;nbsp;&amp;nbsp;&lt;EM&gt;Resource handles obtained in FCMP user functions or subroutines can be passed back to the caller as part of a legitimate coding/framework architecture, so are not auto freed.&lt;/EM&gt;&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;My DATA Step habit is to let the step do it's auto close and deletion of open resources.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 22:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-exit-a-Proc-FCMP-SUBROUTINE-early/m-p/958471#M374070</guid>
      <dc:creator>RichardAD</dc:creator>
      <dc:date>2025-02-05T22:48:45Z</dc:date>
    </item>
  </channel>
</rss>

