<?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: Conditonal merge methology in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771901#M245018</link>
    <description>Thanks,&lt;BR /&gt;And when use macro then if is allowed on middle of another macro ?</description>
    <pubDate>Mon, 04 Oct 2021 11:10:59 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-10-04T11:10:59Z</dc:date>
    <item>
      <title>Conditonal merge methology</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771888#M245012</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;May anyone can explain why this code is wrong?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge have
if x=0 then tbl1;
else then tbl2;
;
BY CustID;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And why the solution is to put it in macro as this code below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro conditional_merge;
data want;
merge have
%if x=0 %then tbl1;
%else %then tbl2;
;
BY CustID;
run;
%mend conditional_merge;
%conditional_merge
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Oct 2021 10:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771888#M245012</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-04T10:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditonal merge methology</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771895#M245015</link>
      <description>&lt;P&gt;If you run your code, you get errors. Why? Because IF is not allowed in the middle of some other statement. IF is only allowed in IF-THEN-ELSE statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, your modification to the macro code &lt;A href="https://communities.sas.com/t5/SAS-Programming/merge-If-condition-A-then-data-set1-else-data-set-2/m-p/771392#M244785" target="_self"&gt;that I provided&lt;/A&gt; is not correct and will not run properly, it should say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge have
%if &amp;amp;x=0 %then tbl1;
%else tbl2;
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;note the ampersand, and that %ELSE %THEN is never correct syntax. Why did you change it?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 11:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771895#M245015</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-04T11:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditonal merge methology</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771901#M245018</link>
      <description>Thanks,&lt;BR /&gt;And when use macro then if is allowed on middle of another macro ?</description>
      <pubDate>Mon, 04 Oct 2021 11:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771901#M245018</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-04T11:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Conditonal merge methology</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771902#M245019</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;And when use macro then if is allowed on middle of another macro ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;IF is not macro code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%IF is a macro statement, and has to follow certain rules that apply to it, just like every other SAS command. I am not using %IF in the "middle of another macro". I am using %IF to generate conditional SAS code, in some cases it generates the code TBL1, and in other cases it generates the code TBL2. It's a method to generate TBL1 in some situations and TBL2 in other situations, which seems to be what you want. You can put %IF in the middle of a DATA step command, provided proper data step syntax is produced by %IF.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 11:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/771902#M245019</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-04T11:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Conditonal merge methology</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/772087#M245117</link>
      <description>&lt;P&gt;You need to internalize this first:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The macro processor is a &lt;STRONG&gt;pre&lt;/STRONG&gt;processor which is used to &lt;U&gt;create code&lt;/U&gt;.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Whenever a % or &amp;amp; is encountered in SAS code, the interpreter invokes the preprocessor to resolve these "macro triggers". If this resolves to some text, this text is then included in the code instead of the triggers. Only after that, the code will be interpreted.&lt;/P&gt;
&lt;P&gt;So you can have macro triggers that result in whole steps, or just fragments that are inserted into a bigger whole.&lt;/P&gt;
&lt;P&gt;The final code after macro resolution must be valid to work. IF is not valid within a MERGE.&lt;/P&gt;
&lt;P&gt;The %IF is actually not "part pf the MERGE". It is just part of &lt;EM&gt;program text&lt;/EM&gt;, and it "vanishes" as soon as the macro processor is invoked. The data step compiler never sees it.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 08:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditonal-merge-methology/m-p/772087#M245117</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-05T08:37:17Z</dc:date>
    </item>
  </channel>
</rss>

