<?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: Macros in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622402#M19770</link>
    <description>&lt;P&gt;Do you want to have 7 as result? Or was it just that you wanted to have&amp;nbsp;the code&amp;nbsp;explained?&lt;/P&gt;</description>
    <pubDate>Wed, 05 Feb 2020 10:30:20 GMT</pubDate>
    <dc:creator>newfee</dc:creator>
    <dc:date>2020-02-05T10:30:20Z</dc:date>
    <item>
      <title>Macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622388#M19763</link>
      <description>&lt;P&gt;Question Output is 10 , why not 7?&lt;/P&gt;&lt;P&gt;%Macro mysum(n);&lt;BR /&gt;%if &amp;amp;n &amp;gt; 1 %then %eval(&amp;amp;n + %mysum(%eval(&amp;amp;n-1)));&lt;BR /&gt;%else &amp;amp;n;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%put %mysum(4);&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 09:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622388#M19763</guid>
      <dc:creator>swayto</dc:creator>
      <dc:date>2020-02-05T09:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622392#M19766</link>
      <description>&lt;P&gt;4 + 3 + 2 + 1 = 10.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 09:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622392#M19766</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-05T09:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622393#M19767</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134135"&gt;@swayto&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the mlogic option to display if the condition was evaluated as true or false:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the macro, you have nested conditions :&lt;/P&gt;
&lt;P&gt;n = 4 so the first condition is true -&amp;gt; &lt;FONT color="#339966"&gt;4 +&lt;/FONT&gt; (as 3 is greater than 1, we apply the "if" condition so: &lt;FONT color="#339966"&gt;3 +&amp;nbsp;&lt;/FONT&gt;(as 2 is greater than 1,&amp;nbsp;we apply the "if" condition so:&amp;nbsp;&lt;FONT color="#339966"&gt;2 +&lt;/FONT&gt;&amp;nbsp;(as 1 is not greater than 1, we apply the 'else' condition so&amp;nbsp;&lt;FONT color="#339966"&gt;1&lt;FONT color="#000000"&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;-&amp;gt; so 4 + 3 + 2+ 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it's clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 09:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622393#M19767</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-05T09:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622402#M19770</link>
      <description>&lt;P&gt;Do you want to have 7 as result? Or was it just that you wanted to have&amp;nbsp;the code&amp;nbsp;explained?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 10:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622402#M19770</guid>
      <dc:creator>newfee</dc:creator>
      <dc:date>2020-02-05T10:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622405#M19771</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Output 10 because of recursive code*/
%macro mysum(n);
	%if &amp;amp;n &amp;gt; 1 %then %eval(&amp;amp;n + %mysum(%eval(&amp;amp;n-1)));
	%else &amp;amp;n;
%mend;

options mprint mlogic;
%put %mysum(4);

/*Output 7 because of nonrecursive code*/
%macro mysum(n);
	%if &amp;amp;n &amp;gt; 1 %then %eval(&amp;amp;n + /*%mysum removed*/%eval(&amp;amp;n-1));
	%else &amp;amp;n;
%mend;

options mprint mlogic;
%put %mysum(4);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I hope this helped.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 11:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macros/m-p/622405#M19771</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2020-02-05T11:07:52Z</dc:date>
    </item>
  </channel>
</rss>

