<?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 macro issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106668#M22224</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Quentin and Ballardw!&lt;/P&gt;&lt;P&gt;I didn't do the do loop because I have variable names based on the value of y.&lt;/P&gt;&lt;P&gt;It ended up being the extra semicolons after calling the y macro.&lt;/P&gt;&lt;P&gt;I never knew that having extras of them could be a problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Jul 2012 17:12:03 GMT</pubDate>
    <dc:creator>egoldstein</dc:creator>
    <dc:date>2012-07-13T17:12:03Z</dc:date>
    <item>
      <title>If then else in macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106665#M22221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have code of the following form:&lt;/P&gt;&lt;P&gt;%macro y(y);&lt;/P&gt;&lt;P&gt;else if year=200&amp;amp;y. then do; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;code&amp;gt;; end;&lt;/P&gt;&lt;P&gt;%mend y;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro go(com);&lt;/P&gt;&lt;P&gt;data &amp;amp;com._1 &lt;/P&gt;&lt;P&gt;merge &amp;amp;com._2 &amp;amp;com._3 ;&lt;/P&gt;&lt;P&gt;by type;&lt;/P&gt;&lt;P&gt;if year=2001 then do; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;code&amp;gt;; end;&lt;/P&gt;&lt;P&gt;%y(2); %y(3); %y(4); %y(5); &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend go;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%go(ABC);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When run, I get an error message on the invocation of %y(3), %y(4), and %y(5) that:&lt;/P&gt;&lt;P&gt;ERROR 160-185: No matching IF-THEN clause&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I change the code of the "y" macro to&amp;nbsp; just be an if statement, the problem goes away, but I can't figure out why the problem exists in the first place.&amp;nbsp; Any thoughts on why this is happening?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 15:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106665#M22221</guid>
      <dc:creator>egoldstein</dc:creator>
      <dc:date>2012-07-13T15:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: If then else in macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106666#M22222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use OPTIONS MPRINT ; and then run you %go macro to see what the generated code looks like.&lt;/P&gt;&lt;P&gt;You might also try removing the "." ad 200&amp;amp;y. or other places in your &amp;lt;code&amp;gt; if any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of a macro like %y I would probably do something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Else do year= 2002 to 2005;&lt;/P&gt;&lt;P&gt;&amp;lt;code&amp;gt;&lt;/P&gt;&lt;P&gt;End;&lt;/P&gt;&lt;P&gt;unless code is using the &amp;amp;y values somewhere.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 15:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106666#M22222</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-07-13T15:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: If then else in macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106667#M22223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;MPRINT is a good recommendation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My guess is you have two many extra semicolons.&amp;nbsp; You dont need a semicolon after a macro call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try changing:&lt;/P&gt;&lt;P&gt;%y(2); %y(3); %y(4); %y(5);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To&lt;/P&gt;&lt;P&gt;%y(2) %y(3) %y(4) %y(5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below code shows the same errors caused by extra semicolon creating a null statement.&amp;nbsp; It breaks the else if:&lt;/P&gt;&lt;PRE&gt;options mprint;
%macro y(year);
&amp;nbsp; else if year=&amp;amp;year then x=1;
%mend;

data _null_;
&amp;nbsp; year=1990;

&amp;nbsp; *extra semicolons after macro call cause null statement which breaks else if error;
&amp;nbsp; if year=1 then x=1;
&amp;nbsp; %y(2000);
&amp;nbsp; %y(2001);

&amp;nbsp; *can see same errors without macro, caused by extra semicolon;
&amp;nbsp; if year=1 then x=1;
&amp;nbsp; else if year=2000 then x=1;;
&amp;nbsp; else if year=2001 then x=1;;
run;


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 16:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106667#M22223</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2012-07-13T16:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: If then else in macro issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106668#M22224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Quentin and Ballardw!&lt;/P&gt;&lt;P&gt;I didn't do the do loop because I have variable names based on the value of y.&lt;/P&gt;&lt;P&gt;It ended up being the extra semicolons after calling the y macro.&lt;/P&gt;&lt;P&gt;I never knew that having extras of them could be a problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 17:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-in-macro-issue/m-p/106668#M22224</guid>
      <dc:creator>egoldstein</dc:creator>
      <dc:date>2012-07-13T17:12:03Z</dc:date>
    </item>
  </channel>
</rss>

