<?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 Macro variable not resolved in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918385#M361766</link>
    <description>&lt;P&gt;why are my macro variables not resolved? Do you know it?&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options mprint mlogic;&lt;/P&gt;&lt;P&gt;%macro test;&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(*)&lt;BR /&gt;into :pstn_cc&lt;BR /&gt;from ueberschrift_lesen;&lt;BR /&gt;%let pstn_cc = &amp;amp;pstn_cc;&lt;/P&gt;&lt;P&gt;select pstn&lt;BR /&gt;into :pstn_cn1-:pstn_cn&amp;amp;pstn_cc&lt;BR /&gt;from ueberschrift_lesen;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;pstn_cc;&lt;BR /&gt;%put &amp;amp;pstn_cn&amp;amp;i;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my log:&lt;/P&gt;&lt;P&gt;MLOGIC(TEST): %DO loop beginning; index variable I; start value is 1; stop value is 4; by value is 1.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn1&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable I is now 2; loop will iterate again.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn2&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable I is now 3; loop will iterate again.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn3&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable I is now 4; loop will iterate again.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn4&lt;/P&gt;</description>
    <pubDate>Thu, 29 Feb 2024 11:10:24 GMT</pubDate>
    <dc:creator>Hoibai</dc:creator>
    <dc:date>2024-02-29T11:10:24Z</dc:date>
    <item>
      <title>Macro variable not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918385#M361766</link>
      <description>&lt;P&gt;why are my macro variables not resolved? Do you know it?&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options mprint mlogic;&lt;/P&gt;&lt;P&gt;%macro test;&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(*)&lt;BR /&gt;into :pstn_cc&lt;BR /&gt;from ueberschrift_lesen;&lt;BR /&gt;%let pstn_cc = &amp;amp;pstn_cc;&lt;/P&gt;&lt;P&gt;select pstn&lt;BR /&gt;into :pstn_cn1-:pstn_cn&amp;amp;pstn_cc&lt;BR /&gt;from ueberschrift_lesen;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;pstn_cc;&lt;BR /&gt;%put &amp;amp;pstn_cn&amp;amp;i;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my log:&lt;/P&gt;&lt;P&gt;MLOGIC(TEST): %DO loop beginning; index variable I; start value is 1; stop value is 4; by value is 1.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn1&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable I is now 2; loop will iterate again.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn2&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable I is now 3; loop will iterate again.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn3&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable I is now 4; loop will iterate again.&lt;BR /&gt;MLOGIC(TEST): %PUT &amp;amp;pstn_cn&amp;amp;i&lt;BR /&gt;WARNING: Apparent symbolic reference PSTN_CN not resolved.&lt;BR /&gt;&amp;amp;pstn_cn4&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 11:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918385#M361766</guid>
      <dc:creator>Hoibai</dc:creator>
      <dc:date>2024-02-29T11:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918424#M361767</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;pstn_cn&amp;amp;i;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You reference &lt;U&gt;two&lt;/U&gt; variables here: pstn_cn (which you hever created) and i (which you created in the %DO).&lt;/P&gt;
&lt;P&gt;To indirectly address pstn_cn1, you need to use a double ampersand:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;&amp;amp;pstn_cn&amp;amp;i;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This causes a double pass: in the first, &amp;amp;&amp;amp; is reduced to &amp;amp;, and &amp;amp;i is resolved, so you get&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;pstn_cn1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which can be resolved.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 15:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918424#M361767</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-29T15:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918425#M361768</link>
      <description>&lt;P&gt;That's right. Thanks very much.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 15:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918425#M361768</guid>
      <dc:creator>Hoibai</dc:creator>
      <dc:date>2024-02-29T15:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918430#M361770</link>
      <description>&lt;P&gt;Is there some reason you need transfer the values from actual data into macro variables?&lt;/P&gt;
&lt;P&gt;If so there is no need to run the query twice just to get the count, PROC SQL will count for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%local i pstn_cc;
proc sql noprint;
select pstn
  into :pstn_cn1-
  from ueberschrift_lesen
;
%let pstn_cc = &amp;amp;sqlobs ;
quit;
%do i=1 %to &amp;amp;pstn_cc;
  %put &amp;amp;&amp;amp;pstn_cn&amp;amp;i;
%end;
%mend;
%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem with your code was a missing &amp;amp;.&amp;nbsp; You need two &amp;amp; so that the macro processor will know to reprocess the token after it has resolved the &amp;amp;I on the first pass.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 16:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolved/m-p/918430#M361770</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-29T16:18:17Z</dc:date>
    </item>
  </channel>
</rss>

