<?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: Proc SQL select to create macro - Not running as nested macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523671#M142289</link>
    <description>&lt;P&gt;My bad.&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;ProcMAC_Diaphragm&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a macro&amp;nbsp; variable&amp;nbsp; value in the macro call and not a macro parameter. I think I have to go and get my eyes checked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macname is a local macro variable that is local to the macro definition makemac. Sorry I am just waking up. Holiday laziness. Ignore my previous post&lt;/P&gt;</description>
    <pubDate>Thu, 27 Dec 2018 17:23:24 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-12-27T17:23:24Z</dc:date>
    <item>
      <title>Proc SQL select to create macro - Not running as nested macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523659#M142286</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the SQL procedure to create macros as written below.&amp;nbsp; When I write the code below, macros are created as desired and work as global macros outside the SQL procedure.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select quote(strip(diagnosis)) into :PregnanacyDiag separated by ',' from PregnancyDiag;
quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;PregnanacyDiag; /*appropriate code is written to the log*/&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am using the above procedure many times to create macro variables containing quoted strings of code&amp;nbsp;from numerous datasets which contain procedural, diagnostic, and drug codes.&amp;nbsp; Accordingly, it makes sense to convert this code into a macro.&amp;nbsp; I attempted to do so as show below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro makemac(var,macname,dataset); 
    select quote(strip(&amp;amp;var)) into :&amp;amp;macname separated by ',' from &amp;amp;dataset;
%mend;

proc sql noprint;
     /*Diaphragm Lookup Codes*/
     %makemac(procedure,ProcMAC_Diaphragm,DiaphragmProc);
     %makemac(ndc,NdcMAC_Diaphragm,DiaphramNDC);
     /*Implant Lookup Codes*/
     %makemac(diagnosis,DiagMAC_Implant,ImplantDiag);
     %makemac(procedure,ProcMAC_Implant, ImplantProc);
     %makemac(ndc,NdcMAC_Implant,ImplantNDC);
quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;ProcMAC_Diaphragm;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I expected that the SQL procedure would run as normal with the '%makemac' macro inserting appropriate syntax for select statements for each line of code.&amp;nbsp; When I run the program, the log appears normal.&amp;nbsp; I used the 'symbolgen' option, and it shows the appropriate values replaced for each line of macro code.&amp;nbsp; But when I try to use the '%put &amp;amp;(macro name)' statement, it does not write the string of quoted code to the log I expected, and I receive instead the warning below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"WARNING: Apparent symbolic reference PROCMAC_DIAPHRAGM not resolved."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone could offer suggestions to fix this, I would greatly appreciate it.&amp;nbsp; I am using this code many times.&amp;nbsp; When I hard code it, it works as desired.&amp;nbsp; But&amp;nbsp;streamlining the code as a macro makes more sense to me.&amp;nbsp; Also, I'd just like to understand the error.&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;Ted&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 16:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523659#M142286</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2018-12-27T16:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL select to create macro - Not running as nested macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523669#M142287</link>
      <description>&lt;P&gt;Unfortunately&amp;nbsp;&lt;SPAN&gt;PROCMAC_DIAPHRAGM&amp;nbsp;is a local macro variable and your %put happens to execute outside the macro definition&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Macro parameters are local&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 17:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523669#M142287</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-27T17:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL select to create macro - Not running as nested macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523670#M142288</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Thank you for clarifying this. I guess I will have to figure out a different strategy.</description>
      <pubDate>Thu, 27 Dec 2018 17:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523670#M142288</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2018-12-27T17:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL select to create macro - Not running as nested macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523671#M142289</link>
      <description>&lt;P&gt;My bad.&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;ProcMAC_Diaphragm&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a macro&amp;nbsp; variable&amp;nbsp; value in the macro call and not a macro parameter. I think I have to go and get my eyes checked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macname is a local macro variable that is local to the macro definition makemac. Sorry I am just waking up. Holiday laziness. Ignore my previous post&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 17:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523671#M142289</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-27T17:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL select to create macro - Not running as nested macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523672#M142290</link>
      <description>&lt;P&gt;To make your variables global instead of local, change the macro definition.&amp;nbsp; Currently, you have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; makemac&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;macname&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;dataset&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
    &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;quote&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; :&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;macname separated &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;','&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;dataset&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; makemac&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;macname&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;dataset&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
    %global &amp;amp;macname;&lt;BR /&gt;&lt;SPAN class="token statement"&gt;    select&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;quote&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; :&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;macname separated &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;','&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;dataset&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem isn't that MACNAME is a parameter.&amp;nbsp; &amp;amp;MACNAME is not a parameter.&amp;nbsp; But the problem is that SQL creates its macro variables in the local symbol table.&amp;nbsp; So define them as global ahead of time, as shown above.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 17:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523672#M142290</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-27T17:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL select to create macro - Not running as nested macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523673#M142291</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your suggestion.&amp;nbsp; That was a quick and easy fix.&amp;nbsp; I had played with %global previously, but without success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ted&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 17:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523673#M142291</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2018-12-27T17:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL select to create macro - Not running as nested macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523674#M142292</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for clarifying the definitions.&amp;nbsp; I am still learning macro language and proc sql.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 17:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-select-to-create-macro-Not-running-as-nested-macro/m-p/523674#M142292</guid>
      <dc:creator>LEINAARE</dc:creator>
      <dc:date>2018-12-27T17:33:51Z</dc:date>
    </item>
  </channel>
</rss>

