<?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 SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531190#M145346</link>
    <description>Thanks for suggestions. I would keep this in mind.</description>
    <pubDate>Tue, 29 Jan 2019 21:40:44 GMT</pubDate>
    <dc:creator>jaiganesh</dc:creator>
    <dc:date>2019-01-29T21:40:44Z</dc:date>
    <item>
      <title>Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531007#M145257</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can Anybody please clarify below question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&lt;STRONG&gt;Can a macro create within another macro? If so, how would SAS know where the current macro ended and the new one began? &lt;/STRONG&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jaiganesh&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 15:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531007#M145257</guid>
      <dc:creator>jaiganesh</dc:creator>
      <dc:date>2019-01-29T15:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531030#M145274</link>
      <description>&lt;P&gt;Maxim 4: Try It.&lt;/P&gt;
&lt;P&gt;Run this code and look at the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro inner;
%put inner;
%mend;
%put end of outer;
%mend;

%outer

%inner&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jan 2019 15:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531030#M145274</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-29T15:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531033#M145277</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;showed, it can be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, good programmers consider that bad practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to follow this type of code is to add to your %MEND statements, naming the macro being ended:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend inner;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend outer;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not a requirement, it just is easier to follow.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 15:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531033#M145277</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-29T15:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531045#M145278</link>
      <description>&lt;P&gt;An addendum: all macros are always defined in the global symbol table, so nesting macro definitions only causes confusion when reading the code, but serves no other purpose. &lt;STRONG&gt;DON'T DO IT&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 16:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531045#M145278</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-29T16:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531060#M145287</link>
      <description>&lt;P&gt;You can, but you should never do this. It's really bad practice, and I've never come across such a use case in 15+ years. It can be done, but there are usually better ways.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4" color="#800080"&gt;&lt;STRONG&gt;%macro embeddedexample;&lt;/STRONG&gt;&lt;/FONT&gt;

proc print data=sashelp.class (obs=2);
run;

&lt;FONT size="4" color="#339966"&gt;&lt;STRONG&gt;%macro test;&lt;/STRONG&gt;&lt;/FONT&gt;

proc print data=sashelp.cars (obs=5);
run;

&lt;FONT size="4"&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;%mend test;&lt;/STRONG&gt;&lt;/FONT&gt;

&lt;FONT color="#800080"&gt;&lt;STRONG&gt;%mend embeddedexample;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;


%embeddedexample;

%test;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240933"&gt;@jaiganesh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can Anybody please clarify below question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;STRONG&gt;Can a macro create within another macro? If so, how would SAS know where the current macro ended and the new one began? &lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jaiganesh&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 16:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531060#M145287</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-29T16:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531061#M145288</link>
      <description>&lt;P&gt;Are you asking about actual macros or perhaps you mean macro variables (aka symbols) instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To let the macro processor know where the name of the macro variable being referenced ends use a period.&lt;/P&gt;
&lt;P&gt;So this code is looking for a macro variable named XXS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let xx=dataset;
%let n=32;
%put There are &amp;amp;n &amp;amp;xxs.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But this code is looking for a macro variable named XX and appending the letter s and a period to the result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put There are &amp;amp;n &amp;amp;xx.s.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 16:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531061#M145288</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-29T16:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531190#M145346</link>
      <description>Thanks for suggestions. I would keep this in mind.</description>
      <pubDate>Tue, 29 Jan 2019 21:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macros/m-p/531190#M145346</guid>
      <dc:creator>jaiganesh</dc:creator>
      <dc:date>2019-01-29T21:40:44Z</dc:date>
    </item>
  </channel>
</rss>

