<?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: How do I use proc sql's :into-function inside a macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188917#M35693</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think your macrovariable does not exist after the macro run. Try to move the %put statement inside the macro and see what happens. If you want the macro variable to be accessible after the macro is executed you can either use the %global statement or just create the variables before the macro run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By creation I mean for example %let diag2=;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jakub&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Jan 2015 14:20:52 GMT</pubDate>
    <dc:creator>chrej5am</dc:creator>
    <dc:date>2015-01-19T14:20:52Z</dc:date>
    <item>
      <title>How do I use proc sql's :into-function inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188916#M35692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to execute the following code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%MACRO sks(START,STOP);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%DO ite = &amp;amp;START %TO &amp;amp;STOP;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;select diagkode&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;into :diag&amp;amp;ite separated by ','&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;from sks_a(where=(diag_23=&amp;amp;ite));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%END;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%mend sks;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%sks(1,23);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%put &amp;amp;diag2; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The log says:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;MLOGIC(SKS):&amp;nbsp; %DO loop index variable ITE is now 24; loop will not iterate again. MLOGIC(SKS):&amp;nbsp; Ending execution.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it seems like it executes the whole thing. But when I run &lt;SPAN style="color: #3366ff;"&gt;%put &amp;amp;diag2&lt;/SPAN&gt;; I get the message &lt;SPAN style="color: #3366ff;"&gt;WARNING: Apparent symbolic reference DIAG2 not resolved&lt;/SPAN&gt;. So somehow it doesn't create the macrovariables. If I just run the proc sql by itself it works fine (see the code below) so the problem arises, when I put it inside a macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bedste regards,&lt;/P&gt;&lt;P&gt;Jacob Hornnes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code to the sql which runs fine:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;select diagkode&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;into :diag1 separated by ','&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;from sks_a(where=(diag_23=1));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3366ff;"&gt;%put &amp;amp;diag1;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jan 2015 14:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188916#M35692</guid>
      <dc:creator>JacobH</dc:creator>
      <dc:date>2015-01-19T14:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use proc sql's :into-function inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188917#M35693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think your macrovariable does not exist after the macro run. Try to move the %put statement inside the macro and see what happens. If you want the macro variable to be accessible after the macro is executed you can either use the %global statement or just create the variables before the macro run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By creation I mean for example %let diag2=;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jakub&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jan 2015 14:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188917#M35693</guid>
      <dc:creator>chrej5am</dc:creator>
      <dc:date>2015-01-19T14:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use proc sql's :into-function inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188918#M35694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since the SQL is executing inside the macro, they are probably defined as local.&lt;/P&gt;&lt;P&gt;Adding a %GLOBAL statement within %DO loop will solve your problem, if you need them outside the macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jan 2015 14:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188918#M35694</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-01-19T14:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use proc sql's :into-function inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188919#M35695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for sure they are local what else, the result of that being removed after the execution of the macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jan 2015 14:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188919#M35695</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2015-01-19T14:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use proc sql's :into-function inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188920#M35696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much, both of you! I just changed the code, adding the %global statement, and know it works perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The now functioning code is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO sks(START,STOP);&lt;/P&gt;&lt;P&gt; %DO ite = &amp;amp;START %TO &amp;amp;STOP;&lt;/P&gt;&lt;P&gt;%global diag&amp;amp;ite;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select diagkode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;into :diag&amp;amp;ite separated by ','&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from sks_a(where=(diag_23=&amp;amp;ite));&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%END;&lt;/P&gt;&lt;P&gt;%mend sks;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%sks(1,23);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;diag2; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;diag23; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jan 2015 14:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188920#M35696</guid>
      <dc:creator>JacobH</dc:creator>
      <dc:date>2015-01-19T14:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use proc sql's :into-function inside a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188921#M35697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Linus Hjorth provides the reason and solution, I would question why you are doing this.&amp;nbsp; Is there really a reason to create x number of macro variable lists?&amp;nbsp; Are you going to code all your programs using macro lists?&amp;nbsp; There are generally better ways, e.g. normalizing data, using by groups, arrays, code generation, hash tables, clever SQL joining etc.&amp;nbsp; Without knowing your requirements its a bit hard to say, but this should simplify creating macro lists (if that is what you really need to do):&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; diagkode="AB"; diag_23=1; output;&lt;BR /&gt;&amp;nbsp; diagkode="CD"; diag_23=1; output;&lt;BR /&gt;&amp;nbsp; diagkode="RT"; diag_23=2; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=inter;&lt;BR /&gt;&amp;nbsp; by diag_23;&lt;BR /&gt;&amp;nbsp; var diagkode;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; set inter;&lt;BR /&gt;&amp;nbsp; array col{2}; /* Note you can get this by max(diag_23) */&lt;BR /&gt;&amp;nbsp; call symput('DIAG'||strip(put(diag_23,best.)),catx(',',of col(*)));&lt;BR /&gt;run;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;%put &amp;amp;diag1.;&lt;BR /&gt;%put &amp;amp;diag2.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jan 2015 14:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-proc-sql-s-into-function-inside-a-macro/m-p/188921#M35697</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-19T14:46:10Z</dc:date>
    </item>
  </channel>
</rss>

