<?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: macro variable with iterating name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304641#M64856</link>
    <description>&lt;P&gt;The %put is dealt with by the macro processor &lt;U&gt;immediately&lt;/U&gt; when encountered, which means before the data step is &lt;U&gt;compiled&lt;/U&gt;. But the call symput executes during data step &lt;U&gt;execution&lt;/U&gt; phase, so &amp;amp;keyX (X being 1 to 7) will never exist when the %put is executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Short: you cannot %put a macro variable before the data step that creates it with call symput() has &lt;U&gt;run&lt;/U&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2016 12:39:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-10-14T12:39:54Z</dc:date>
    <item>
      <title>macro variable with iterating name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304632#M64852</link>
      <description>&lt;P&gt;So, I'm writing a macro that at a certain point must save the content of a record variable on a macro variable with incrementing name depending on the position of the table. This is a fragment&lt;/P&gt;&lt;PRE&gt;		%do i=1 %to 7;
			IF _n_ GT (4095*&amp;amp;i-4095) AND _n_ LT (4095*&amp;amp;i) THEN
				DO;
					key&amp;amp;i.=trim(key&amp;amp;i.)!!' '!!trim(left(m));
					IF _n_ EQ (4095*&amp;amp;i-1) THEN
					DO;
						CALL SYMPUT('key'||LEFT(&amp;amp;i), trim(key&amp;amp;i));
						DROP key&amp;amp;i;
						%PUT &amp;amp;&amp;amp;key&amp;amp;i;
					END;
				end;
		%end;&lt;/PRE&gt;&lt;P&gt;I want to save the the macro variable called key1 to key6 to the value of the &amp;nbsp;variable key1 to key6 at intervals of&amp;nbsp;4095.&lt;/P&gt;&lt;P&gt;I know this program is conceptually wrong, terrible and makes me sick in the stomach, but I'm not permitted to redesign it so I have to solve this problem.&lt;/P&gt;&lt;P&gt;The log says "WARNING: Apparent symbolic reference KEY1 not resolved.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 12:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304632#M64852</guid>
      <dc:creator>Crysis85</dc:creator>
      <dc:date>2016-10-14T12:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with iterating name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304633#M64853</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess the message comes from the line&lt;/P&gt;
&lt;PRE&gt;%PUT &amp;amp;&amp;amp;key&amp;amp;i;&lt;/PRE&gt;
&lt;P&gt;Try commenting it and see if it works. &lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 12:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304633#M64853</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-10-14T12:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with iterating name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304635#M64854</link>
      <description>&lt;P&gt;This code is invalid as its stands, where is the rest of it. &amp;nbsp;You are mixing Base SAS statements in with Macro statements, you are using macro variables from call symput statements - and this is about the time when things get compiled - but those macro variables have not been executed yet etc. &amp;nbsp;So think of it this way, when that is pushed through the macro compiler, the call execute has not run, so %put cannot find a macro variable call &amp;amp;key1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this statement "&lt;SPAN&gt;but I'm not permitted to redesign it", really shouldn't be the case, if something is wrong it should be fixed, not perpetuated.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is basically a very simple dataset problem.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.cars;
  retain i;
  if _n_=1 then i=1;
  if mod(_n_,100)=0 then do;
    call symput(cat('key',put(i,1.)),model);
    i=i+1;
  end;
run;

&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Although why you want to create X amount of macro variables is beyond me, sounds like th ewhole process is a bit shaky.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 12:25:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304635#M64854</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-14T12:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with iterating name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304641#M64856</link>
      <description>&lt;P&gt;The %put is dealt with by the macro processor &lt;U&gt;immediately&lt;/U&gt; when encountered, which means before the data step is &lt;U&gt;compiled&lt;/U&gt;. But the call symput executes during data step &lt;U&gt;execution&lt;/U&gt; phase, so &amp;amp;keyX (X being 1 to 7) will never exist when the %put is executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Short: you cannot %put a macro variable before the data step that creates it with call symput() has &lt;U&gt;run&lt;/U&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 12:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304641#M64856</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-14T12:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with iterating name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304642#M64857</link>
      <description>&lt;P&gt;I understand the problem. I put the %PUT (oh boy) there only to check if the macro variables were written, didn't think about the order on witch are executed, my bad&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 12:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-iterating-name/m-p/304642#M64857</guid>
      <dc:creator>Crysis85</dc:creator>
      <dc:date>2016-10-14T12:42:21Z</dc:date>
    </item>
  </channel>
</rss>

