<?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: if then else in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781981#M249254</link>
    <description>&lt;P&gt;Two things are missing:&lt;/P&gt;
&lt;P&gt;1. defining your macro is not enough, you need to call it as well (after macro definition has run)!&lt;/P&gt;
&lt;P&gt;2. you need to make your macro variable &lt;EM&gt;header&lt;/EM&gt; global, otherwise it is not known outside the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's corrected code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let source = TABLE.TEST1;
%put &amp;amp;=source;

%macro test;
%GLOBAL header;
%if &amp;amp;source eq TABLE.TEST1 %then %let header = &amp;amp;source;
%else %let header = 'TABLE.TEST2';
%mend test;
%test

%put &amp;amp;=header;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Tue, 23 Nov 2021 15:44:50 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-11-23T15:44:50Z</dc:date>
    <item>
      <title>if then else in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781977#M249252</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to create an if statement in a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've used examples found in this forum but I cannot get it to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is my dummy example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let source = TABLE.TEST1;

%put &amp;amp;source;

%macro test;

%if &amp;amp;source eq TABLE.TEST1 %then %let header = &amp;amp;source;

%else %let header = 'TABLE.TEST2';
%mend test;

%put &amp;amp;header;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it does not assign any value to &amp;amp;header (the log says "Apparent symbolic reference not resolved" ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really don't see what am doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 15:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781977#M249252</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2021-11-23T15:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: if then else in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781981#M249254</link>
      <description>&lt;P&gt;Two things are missing:&lt;/P&gt;
&lt;P&gt;1. defining your macro is not enough, you need to call it as well (after macro definition has run)!&lt;/P&gt;
&lt;P&gt;2. you need to make your macro variable &lt;EM&gt;header&lt;/EM&gt; global, otherwise it is not known outside the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's corrected code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let source = TABLE.TEST1;
%put &amp;amp;=source;

%macro test;
%GLOBAL header;
%if &amp;amp;source eq TABLE.TEST1 %then %let header = &amp;amp;source;
%else %let header = 'TABLE.TEST2';
%mend test;
%test

%put &amp;amp;=header;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 15:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781981#M249254</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-11-23T15:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: if then else in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781984#M249256</link>
      <description>&lt;P&gt;You never called the macro. Also if you do not already have a macro variable named HEADER then the %LET statements in the macro will create a LOCAL macro variable which will disappear when the macro finishes running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One simple fix is to just define the macro variable HEADER before calling the macro.&amp;nbsp; Also why are you putting quotes into HEADER sometimes and not other times?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%if &amp;amp;source eq TABLE.TEST1 %then %let header = &amp;amp;source;
%else %let header = TABLE.TEST2;
%mend test;

%let source = TABLE.TEST1;
%let header = ;
%test;
%put &amp;amp;=header &amp;amp;=source;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Nov 2021 15:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781984#M249256</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-23T15:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: if then else in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781985#M249257</link>
      <description>&lt;P&gt;In addition to the above useful advice, also there is almost never a good reason for enclosing the value of a macro variable in quotes or double-quotes. So&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%else %let header = 'TABLE.TEST2';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;probably should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%else %let header = TABLE.TEST2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Nov 2021 15:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/781985#M249257</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-23T15:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: if then else in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/782009#M249266</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yes completely missed calling the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;no reason why I put it in quotes; noted for the next time!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&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, 23 Nov 2021 17:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/782009#M249266</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2021-11-23T17:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: if then else in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/782010#M249267</link>
      <description>&lt;P&gt;many thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;all understood, now works a treat!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 17:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-in-a-macro/m-p/782010#M249267</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2021-11-23T17:13:15Z</dc:date>
    </item>
  </channel>
</rss>

