<?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: To stop the sas code if the condition fail in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115878#M292989</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recommend the %goto function to skip the rest of the statements in the event of certain logic. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; This program is straight out of the sas help library: &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000209058.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000209058.htm"&gt;SAS(R) 9.2 Macro Language: Reference&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %local status;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if /***Insert logic here ***/ %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put NOTE: /* your warning message */;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %goto exit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="emphMono" style="font-family: monospace, 'courier new', courier, fixed; font-style: italic;"&gt;more macro statements that test for error conditions &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put Check completed successfully.;&lt;/P&gt;&lt;P&gt;%exit:&lt;/P&gt;&lt;P&gt;%mend check;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Aug 2013 07:30:38 GMT</pubDate>
    <dc:creator>Murray_Court</dc:creator>
    <dc:date>2013-08-20T07:30:38Z</dc:date>
    <item>
      <title>To stop the sas code if the condition fail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115877#M292988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a sas code which check for the value(true/false). If true continue running the code and if fails exit the sas code without running the steps after.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to create a macro so that i can include this as %include in all the codes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;macro:&lt;/P&gt;&lt;P&gt;check if the value is true/false&lt;/P&gt;&lt;P&gt;if true continue the code&lt;/P&gt;&lt;P&gt;fail exit the program&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 07:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115877#M292988</guid>
      <dc:creator>HashimBasheer</dc:creator>
      <dc:date>2013-08-20T07:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: To stop the sas code if the condition fail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115878#M292989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recommend the %goto function to skip the rest of the statements in the event of certain logic. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; This program is straight out of the sas help library: &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000209058.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000209058.htm"&gt;SAS(R) 9.2 Macro Language: Reference&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %local status;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if /***Insert logic here ***/ %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put NOTE: /* your warning message */;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %goto exit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="emphMono" style="font-family: monospace, 'courier new', courier, fixed; font-style: italic;"&gt;more macro statements that test for error conditions &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put Check completed successfully.;&lt;/P&gt;&lt;P&gt;%exit:&lt;/P&gt;&lt;P&gt;%mend check;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 07:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115878#M292989</guid>
      <dc:creator>Murray_Court</dc:creator>
      <dc:date>2013-08-20T07:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: To stop the sas code if the condition fail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115879#M292990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Murray &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have this option. But the issue is I have data steps after the macro. I dont want to run those data steps if the condition fail. Is there a way I can exit them as well?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 07:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115879#M292990</guid>
      <dc:creator>HashimBasheer</dc:creator>
      <dc:date>2013-08-20T07:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: To stop the sas code if the condition fail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115880#M292991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can issue the ENDSAS statement conditionally in a macro, if you need to issue a RC, take a look at ABORT ABEND.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 07:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115880#M292991</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-08-20T07:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: To stop the sas code if the condition fail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115881#M292992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Linus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You need to put everything that you want to execute conditionally inside the macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*compile macro */&lt;/P&gt;&lt;P&gt;%macro conditional;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if /***Insert logic here ***/ %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put NOTE: /* your warning message */;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %goto exit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put NOTE: Logic determines that data steps will run normally.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; put your further data steps here&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%exit:&lt;/P&gt;&lt;P&gt;%mend conditional;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*execute macro*/&lt;/P&gt;&lt;P&gt;%conditional&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although probably a better idea would be to put your data stepc etc. in a macro and then execute the macro conditionally.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro conditional2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* data steps and everything that you want to execute conditionally */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend conditional2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro execute;&lt;/P&gt;&lt;P&gt;%if 1=0 %then %do;&lt;BR /&gt;%conditonal2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*this calls our previously compiled (but until not not exsecuted) macro */&lt;BR /&gt;%end;&lt;BR /&gt;%else %put NOTE: Logic indicates that data steps will not be executed;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend execute;&lt;/P&gt;&lt;P&gt;%execute&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 08:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115881#M292992</guid>
      <dc:creator>Murray_Court</dc:creator>
      <dc:date>2013-08-20T08:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: To stop the sas code if the condition fail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115882#M292993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I feel like we have 2 options.&lt;/P&gt;&lt;P&gt;1. Bring all the steps into the macro and then use goto/getout to exit the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro validation;&lt;/P&gt;&lt;P&gt;%if condition %then %do;&lt;/P&gt;&lt;P&gt; %goto getout;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;% else %do;&lt;/P&gt;&lt;P&gt;steps1l&lt;/P&gt;&lt;P&gt;steps2;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;2. Two macros. one for checking the conditions and then triggering the datasteps which can be saved in another macro ;&lt;/P&gt;&lt;P&gt;%macro validation;&lt;/P&gt;&lt;P&gt;%if condition %then %do;&lt;/P&gt;&lt;P&gt; %goto getout;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;% else %do;&lt;/P&gt;&lt;P&gt;call all the steps as new macro&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 08:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-stop-the-sas-code-if-the-condition-fail/m-p/115882#M292993</guid>
      <dc:creator>HashimBasheer</dc:creator>
      <dc:date>2013-08-20T08:50:49Z</dc:date>
    </item>
  </channel>
</rss>

