<?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 Turning local macro variable into global using proc sql into: in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Turning-local-macro-variable-into-global-using-proc-sql-into/m-p/372266#M88991</link>
    <description>&lt;P&gt;I am creating macro variables inside of a do loop using the proc sql's&amp;nbsp;into:, I understand that because it is inside a macro function that they are local. How do I transform to global? %global statement doesnt&amp;nbsp;seem to be working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error&lt;/P&gt;&lt;P&gt;ERROR: Attempt to %GLOBAL a name (IDS2) which exists in a local environment. SAS 9.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro num;
	proc sql;
		create table list1 as
		select distinct customerid from payments;
	quit;

   	%do i = 1 %to 6;
	
   		proc sql noprint;
   			select customerid into: ids&amp;amp;i separated by ' '
   			from list1
				where monotonic() between ((6553*&amp;amp;i)-6552) and (6553*&amp;amp;i); 
	
   		quit;
   &lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;&lt;STRONG&gt;%global ids&amp;amp;i;&lt;/STRONG&gt;&lt;BR /&gt;              &lt;FONT color="#000000"&gt;  %end;&lt;/FONT&gt;&lt;/FONT&gt;
   %mend num;
   %num;&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Jun 2017 17:54:07 GMT</pubDate>
    <dc:creator>mhodge20</dc:creator>
    <dc:date>2017-06-30T17:54:07Z</dc:date>
    <item>
      <title>Turning local macro variable into global using proc sql into:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Turning-local-macro-variable-into-global-using-proc-sql-into/m-p/372266#M88991</link>
      <description>&lt;P&gt;I am creating macro variables inside of a do loop using the proc sql's&amp;nbsp;into:, I understand that because it is inside a macro function that they are local. How do I transform to global? %global statement doesnt&amp;nbsp;seem to be working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error&lt;/P&gt;&lt;P&gt;ERROR: Attempt to %GLOBAL a name (IDS2) which exists in a local environment. SAS 9.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro num;
	proc sql;
		create table list1 as
		select distinct customerid from payments;
	quit;

   	%do i = 1 %to 6;
	
   		proc sql noprint;
   			select customerid into: ids&amp;amp;i separated by ' '
   			from list1
				where monotonic() between ((6553*&amp;amp;i)-6552) and (6553*&amp;amp;i); 
	
   		quit;
   &lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;&lt;STRONG&gt;%global ids&amp;amp;i;&lt;/STRONG&gt;&lt;BR /&gt;              &lt;FONT color="#000000"&gt;  %end;&lt;/FONT&gt;&lt;/FONT&gt;
   %mend num;
   %num;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 17:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Turning-local-macro-variable-into-global-using-proc-sql-into/m-p/372266#M88991</guid>
      <dc:creator>mhodge20</dc:creator>
      <dc:date>2017-06-30T17:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Turning local macro variable into global using proc sql into:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Turning-local-macro-variable-into-global-using-proc-sql-into/m-p/372270#M88993</link>
      <description>&lt;P&gt;Did you try:&lt;/P&gt;
&lt;PRE&gt;%macro num;
	proc sql;
		create table list1 as
		select distinct customerid from payments;
	quit;

   	%do i = 1 %to 6;
   &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;%global ids&amp;amp;i;&lt;/STRONG&gt;&lt;/FONT&gt;
	
   		proc sql noprint;
   			select customerid into: ids&amp;amp;i separated by ' '
   			from list1
				where monotonic() between ((6553*&amp;amp;i)-6552) and (6553*&amp;amp;i); 
	
   		quit;
                %end;
   %mend num;
   %num;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 18:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Turning-local-macro-variable-into-global-using-proc-sql-into/m-p/372270#M88993</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-30T18:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Turning local macro variable into global using proc sql into:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Turning-local-macro-variable-into-global-using-proc-sql-into/m-p/372285#M88997</link>
      <description>&lt;P&gt;Looks like you're creating a series of macro variables based on the number of observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be worthwhile to consider a data step solution instead, where you don't really need a macro at all and can use CALL SYMPUTX to create the macro variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
length value_list $32562.;

if _n_ =1 then i=1;

value_list = catx(" ", trim(value_list), id);

if _N_ &amp;gt;= i*6534 then do;
call symputx ('myvar'||i, value_list, 'g');
i+1;
call missing(value_list);
end;

run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Here's an untested sketch of how that may look.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 19:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Turning-local-macro-variable-into-global-using-proc-sql-into/m-p/372285#M88997</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-30T19:29:46Z</dc:date>
    </item>
  </channel>
</rss>

