<?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: Run the whole code on the base of condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603964#M175029</link>
    <description>&lt;P&gt;Thank you, moving to a seperate location worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Nov 2019 20:40:11 GMT</pubDate>
    <dc:creator>AJ_Brien</dc:creator>
    <dc:date>2019-11-13T20:40:11Z</dc:date>
    <item>
      <title>Run the whole code on the base of condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603707#M174925</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a huge piece of code which contains multiple data steps, macros, proc sqls, loops etc. such that this entire piece of code needs to run only if a certain condition is met.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
now=today();
d=day(now);
put d;
if d in (30,31,1,2,3,4) then call symput ('run','N');
else call symput ('run','Y');
run;
%put &amp;amp;run.;&lt;BR /&gt;&lt;BR /&gt;%macro selection;&lt;BR /&gt;[entire&amp;nbsp;code: data steps, macros, proc sqls, loops etc. ]&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;%if &amp;amp;run.='Y' %then %do;&lt;BR /&gt;%selection;&lt;BR /&gt;end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the error that I get:&lt;/P&gt;&lt;P&gt;975 data _null_;&lt;BR /&gt;976 %if &amp;amp;run.='Y' %then %do;&lt;BR /&gt;ERROR: Nesting of %IF statements in open code is not supported. %IF ignored.&lt;BR /&gt;ERROR: Skipping to next %END statement.&lt;BR /&gt;977 %selection;&lt;BR /&gt;MLOGIC(SELECTION): Beginning execution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would there be a way to conditionally execute a huge piece of code?&lt;/P&gt;&lt;P&gt;Appreciate the help!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 20:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603707#M174925</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-12T20:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Run the whole code on the base of condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603708#M174926</link>
      <description>&lt;P&gt;Separate your steps. Put all the code that needs to be run in a separate program. &lt;BR /&gt;Create your condition and only execute it if the condition was met. You can use %INCLUDE to run a program. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
now=today();
d=day(now);
put d;
if d in (30,31,1,2,3,4) then call execute ('%include "path to  sas program.sas" / lrecl=500');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The program with the data set becomes your control program that executes the remaining code if necessary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can make this more convoluted if you'd like, look at macro logic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank" rel="noopener"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265086"&gt;@AJ_Brien&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a huge piece of code which contains multiple data steps, macros, proc sqls, loops etc. such that this entire piece of code needs to run only if a certain condition is met.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
now=today();
d=day(now);
put d;
if d in (30,31,1,2,3,4) then call symput ('run','N');
else call symput ('run','Y');
run;
%put &amp;amp;run.;&lt;BR /&gt;&lt;BR /&gt;%macro selection;&lt;BR /&gt;[entire&amp;nbsp;code: data steps, macros, proc sqls, loops etc. ]&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;%if &amp;amp;run.='Y' %then %do;&lt;BR /&gt;%selection;&lt;BR /&gt;end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the error that I get:&lt;/P&gt;
&lt;P&gt;975 data _null_;&lt;BR /&gt;976 %if &amp;amp;run.='Y' %then %do;&lt;BR /&gt;ERROR: Nesting of %IF statements in open code is not supported. %IF ignored.&lt;BR /&gt;ERROR: Skipping to next %END statement.&lt;BR /&gt;977 %selection;&lt;BR /&gt;MLOGIC(SELECTION): Beginning execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would there be a way to conditionally execute a huge piece of code?&lt;/P&gt;
&lt;P&gt;Appreciate the help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 21:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603708#M174926</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-12T21:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Run the whole code on the base of condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603709#M174927</link>
      <description>&lt;P&gt;You don't need macro. Put your required code in a separate SAS program file then use %INCLUDE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if &amp;lt;condition is true&amp;gt; then do;
   call execute('%include "MyLargeProgram.sas";');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Nov 2019 21:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603709#M174927</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-11-12T21:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Run the whole code on the base of condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603711#M174928</link>
      <description>&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;976 %if &amp;amp;run.='Y' %then %do;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Typically, the value of macro variables are not enclosed in quotes, and the way you are creating the macro variable &amp;amp;RUN via CALL SYMPUT, the value created for macro variable &amp;amp;RUN is Y (or N), which is not enclosed in quotes. Thus you are testing to see if the one-letter text string Y (the value of &amp;amp;RUN) is equal to the hard coded text string 'Y', and these are never equal.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thus, you want&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;run.=Y %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;ERROR: Nesting of %IF statements in open code is not supported. %IF ignored.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You need to do this inside a macro or via CALL EXECUTE.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 21:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603711#M174928</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-12T21:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Run the whole code on the base of condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603964#M175029</link>
      <description>&lt;P&gt;Thank you, moving to a seperate location worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2019 20:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/603964#M175029</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-13T20:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Run the whole code on the base of condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/604063#M175080</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265086"&gt;@AJ_Brien&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, moving to a seperate location worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm not sure anyone recommended "moving to a seperate location", so it's not clear what you are saying.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 12:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-the-whole-code-on-the-base-of-condition/m-p/604063#M175080</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-14T12:08:02Z</dc:date>
    </item>
  </channel>
</rss>

