<?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: Calling a Macro from an IF in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716892#M38071</link>
    <description>Your IF syntax is wrong you shouldn't have the semicolon between them. In that case, it ends your IF statement and each macro command will be executed.&lt;BR /&gt;&lt;BR /&gt;data _null_ ;&lt;BR /&gt;&lt;BR /&gt;     if flag = 'T" then &lt;BR /&gt;&lt;BR /&gt;          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;&lt;BR /&gt;&lt;BR /&gt;     else &lt;BR /&gt;&lt;BR /&gt;          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;&lt;BR /&gt;&lt;BR /&gt;run ;&lt;BR /&gt;&lt;BR /&gt;In general though, I'd recommend creating a variable with the parameters and then using that with the macro call. Also, within a data step it's slightly cleaner to use CALL EXEUCTE() to call the macro. The documentation has a good example of CALL EXECUTE. &lt;BR /&gt;&lt;BR /&gt;data _null_ ;&lt;BR /&gt;&lt;BR /&gt;     if flag = 'T" then ;&lt;BR /&gt;&lt;BR /&gt;          call execute('%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext");') ;&lt;BR /&gt;&lt;BR /&gt;     else ;&lt;BR /&gt;&lt;BR /&gt;          call execute('%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext");') ;&lt;BR /&gt;&lt;BR /&gt;run ;</description>
    <pubDate>Thu, 04 Feb 2021 19:27:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-02-04T19:27:40Z</dc:date>
    <item>
      <title>Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716890#M38070</link>
      <description>&lt;P&gt;Good Day!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to call an email macro from an IF based on a stored value. I am sending to different individuals based on the setting of flag.&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;if flag = 'T" then ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;&lt;/P&gt;
&lt;P&gt;run ;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716890#M38070</guid>
      <dc:creator>JeffreyLowe</dc:creator>
      <dc:date>2021-02-04T19:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716892#M38071</link>
      <description>Your IF syntax is wrong you shouldn't have the semicolon between them. In that case, it ends your IF statement and each macro command will be executed.&lt;BR /&gt;&lt;BR /&gt;data _null_ ;&lt;BR /&gt;&lt;BR /&gt;     if flag = 'T" then &lt;BR /&gt;&lt;BR /&gt;          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;&lt;BR /&gt;&lt;BR /&gt;     else &lt;BR /&gt;&lt;BR /&gt;          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;&lt;BR /&gt;&lt;BR /&gt;run ;&lt;BR /&gt;&lt;BR /&gt;In general though, I'd recommend creating a variable with the parameters and then using that with the macro call. Also, within a data step it's slightly cleaner to use CALL EXEUCTE() to call the macro. The documentation has a good example of CALL EXECUTE. &lt;BR /&gt;&lt;BR /&gt;data _null_ ;&lt;BR /&gt;&lt;BR /&gt;     if flag = 'T" then ;&lt;BR /&gt;&lt;BR /&gt;          call execute('%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext");') ;&lt;BR /&gt;&lt;BR /&gt;     else ;&lt;BR /&gt;&lt;BR /&gt;          call execute('%genMail("tomail","ccmail","bcmail","subject","attachment","bodytext");') ;&lt;BR /&gt;&lt;BR /&gt;run ;</description>
      <pubDate>Thu, 04 Feb 2021 19:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716892#M38071</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-04T19:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716893#M38072</link>
      <description>&lt;P&gt;Since the data step variable FLAG never equals "T", you will always execute the ELSE clause, but you have syntax errors and incorrect semi-colons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
     if flag = "T" then 
          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
     else 
          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but I think you might really want a SET statement so FLAG has a value that might be "T"&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;data _null_ ;
    set somedataset;
     if flag = "T" then 
          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
     else 
          %genMail("tomail","ccmail","bcmail","subject","attachment","bodytext") ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then whatever %genmail does can only contain DATA step code, if there's a PROC in there, the whole thing fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, there are lots of problems here. Whether FLAG="T" or not, you execute the same macro with the same arguments. Why?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you ought to start over and explain what you are trying to do, rather than putting up such problematic code and have us guess what you are trying to do.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716893#M38072</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-04T19:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716894#M38073</link>
      <description>&lt;P&gt;Adding:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, that CALL EXECUTE would be a better method of executing this macro if it doesn't contain valid DATA step code.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716894#M38073</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-04T19:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716897#M38074</link>
      <description>&lt;P&gt;Actually flag is set elsewhere based on the data being processed when I entered my example it should say if &amp;amp;flag = 'T'..........&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716897#M38074</guid>
      <dc:creator>JeffreyLowe</dc:creator>
      <dc:date>2021-02-04T19:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716898#M38075</link>
      <description>&lt;P&gt;Thank you Paige!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716898#M38075</guid>
      <dc:creator>JeffreyLowe</dc:creator>
      <dc:date>2021-02-04T19:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716902#M38076</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/318589"&gt;@JeffreyLowe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Actually flag is set elsewhere based on the data being processed when I entered my example it should say if &amp;amp;flag = 'T'..........&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This syntax works only if the value of &amp;amp;FLAG is a character string with quotes around it ... in which case, why even bother with &lt;FONT face="courier new,courier"&gt;DATA _NULL_;&lt;/FONT&gt;? Do it all with macro %IF and not within a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;flag=T %then ... ; /* Note, you don't put macro variable values in quotes */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716902#M38076</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-04T19:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716906#M38077</link>
      <description>As of SAS 9.4 M5+ (I think) you can use %IF in open code and no macro/data step is required.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n18fij8dqsue9pn1lp8436e5mvb7.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n18fij8dqsue9pn1lp8436e5mvb7.htm&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716906#M38077</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-04T19:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a Macro from an IF</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716931#M38078</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/318589"&gt;@JeffreyLowe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Actually flag is set elsewhere based on the data being processed when I entered my example it should say if &amp;amp;flag = 'T'..........&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This syntax works only if the value of &amp;amp;FLAG is a character string with quotes around it ... in which case, why even bother with &lt;FONT face="courier new,courier"&gt;DATA _NULL_;&lt;/FONT&gt;? Do it all with macro %IF and not within a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;flag=T %then ... ; /* Note, you don't put macro variable values in quotes */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Adding to the above ... if you really want to test &amp;amp;flag='T', this is a situation where double quotes and single quotes cannot be mixed and matched. If, for example, the value of &amp;amp;flag is "T", you will not get a match. Only if &amp;amp;flag is 'T' will you get a match, and this doesn't seem like a good way to do the comparison (which is one reason why I say macro variable values should not be enclosed in quotes).&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 22:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-a-Macro-from-an-IF/m-p/716931#M38078</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-04T22:20:02Z</dc:date>
    </item>
  </channel>
</rss>

