<?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: refer a macro variable in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623300#M183475</link>
    <description>&lt;P&gt;Another working approach would be to create the macro variables A and B without quoting functions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   call symput('A', '%do i=1 %to 3;');
   call symput('B', '%end;');
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can use your macro as is.&lt;/P&gt;</description>
    <pubDate>Sat, 08 Feb 2020 15:00:56 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-02-08T15:00:56Z</dc:date>
    <item>
      <title>refer a macro variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623289#M183471</link>
      <description>&lt;P&gt;dear all:&lt;/P&gt;&lt;P&gt;i wanna refer a macro variable in a macro like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a=%nrstr(%do i= 1 %to 3;);
%let b=%nrstr(%end;);
%macro linshi();
&amp;amp;a.;
%put &amp;amp;i.;
&amp;amp;b.;
%mend;
%linshi();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;but the log shows :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "A".&lt;BR /&gt;1 %do i= 1 %to 3;&lt;BR /&gt;-&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;&amp;amp;i.&lt;BR /&gt;NOTE: Line generated by the macro variable "B".&lt;BR /&gt;1 %end;&lt;BR /&gt;-&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What should i do to make it work?&lt;/P&gt;&lt;P&gt;Thanks in advance !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 09:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623289#M183471</guid>
      <dc:creator>duanzongran</dc:creator>
      <dc:date>2020-02-08T09:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: refer a macro variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623298#M183473</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266020"&gt;@duanzongran&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the error messages are due to the (invisible) macro quoting characters which you introduced by (correctly) using the %NRSTR function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The deeper issue is that you want to create macro program &lt;EM&gt;text&lt;/EM&gt;, then &lt;EM&gt;compile&lt;/EM&gt; and finally &lt;EM&gt;execute&lt;/EM&gt; this macro, but you mix the first two of these three steps. The compilation of the %MACRO, %PUT and %MEND statements must be deferred similarly to that of the %DO-%END statements. Here's how you can achieve this (and use&amp;nbsp;the %UNQUOTE function to remove the macro quoting characters):&lt;/P&gt;
&lt;PRE&gt;%let a=%nrstr(%do i= 1 %to 3;);
%let b=%nrstr(%end;);

&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;%unquote(&lt;/FONT&gt;
  &lt;FONT color="#3366FF"&gt;%nrstr(&lt;/FONT&gt;&lt;/STRONG&gt;%macro linshi();&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;
  &amp;amp;a.;
  &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;%nrstr(&lt;/STRONG&gt;&lt;/FONT&gt;%put &amp;amp;i.;&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;
  &amp;amp;b.;
  &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;%nrstr(&lt;/STRONG&gt;&lt;/FONT&gt;%mend;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;)&lt;/FONT&gt;
&lt;FONT color="#3366FF"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;

%linshi();&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Feb 2020 14:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623298#M183473</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-02-08T14:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: refer a macro variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623300#M183475</link>
      <description>&lt;P&gt;Another working approach would be to create the macro variables A and B without quoting functions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   call symput('A', '%do i=1 %to 3;');
   call symput('B', '%end;');
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can use your macro as is.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 15:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623300#M183475</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-08T15:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: refer a macro variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623301#M183476</link>
      <description>&lt;P&gt;Sounds like the old Doctor joke.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The patient says, "Doctor, it hurts when I do this." "Then don't do that!"&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need to dynamically generate code it is going to be much easier to dynamically generate SAS code instead of trying to dynamically generate macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the actual problem you are trying to solve by creating that Rube Goldberg machine?&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 15:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623301#M183476</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-08T15:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: refer a macro variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623313#M183483</link>
      <description>&lt;P&gt;My thoughts, in sequence:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;"This is crazy!"&lt;/LI&gt;
&lt;LI&gt;"This is&amp;nbsp;&lt;EM&gt;absolutely&lt;/EM&gt; crazy!"&lt;/LI&gt;
&lt;LI&gt;"Somebody get help, quickly, for this poor person!"&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Really, what is the purpose of this?&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 16:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623313#M183483</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-08T16:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: refer a macro variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623325#M183497</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have had such thoughts many times about many posts. My tongue has permanent scars from the number and intensity of times I have bitten it. But not in this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To me, this is how you learn about macro language.&amp;nbsp; Try things out, see what works and what doesn't.&amp;nbsp; For the things that don't work, try to figure out why.&amp;nbsp; Then re-test your conclusions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, I can't guarantee the intention here, but I look at this as a learning experience not application development.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 18:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623325#M183497</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-08T18:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: refer a macro variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623431#M183545</link>
      <description>Agreed with others here, this is a very weird way to generate code. If you're actually using this code in production or to do an analysis I'd highly recommend you state your actual intent and someone can help you move towards a better solution. &lt;BR /&gt;&lt;BR /&gt;If you're doing this for the pleasure of learning about macros, have fun.</description>
      <pubDate>Sun, 09 Feb 2020 18:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/refer-a-macro-variable-in-a-macro/m-p/623431#M183545</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-09T18:32:24Z</dc:date>
    </item>
  </channel>
</rss>

