<?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 error Apparent symbolic reference in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561790#M10640</link>
    <description>&lt;P&gt;THank you so much!&lt;/P&gt;</description>
    <pubDate>Mon, 27 May 2019 19:48:15 GMT</pubDate>
    <dc:creator>meckarthik</dc:creator>
    <dc:date>2019-05-27T19:48:15Z</dc:date>
    <item>
      <title>Macro error Apparent symbolic reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561588#M10614</link>
      <description>&lt;P&gt;Getting macro error &amp;nbsp;(Need Help!!!)&lt;/P&gt;&lt;P&gt;Basically I tried to run &amp;nbsp;below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;assign&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(distinct(Identifier)) into :z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from &amp;amp;Olive_Schema.&lt;STRONG&gt;.o&lt;/STRONG&gt;wner_metadata ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let z = &amp;amp;z;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do j = &lt;STRONG&gt;1&lt;/STRONG&gt; %to &amp;amp;z;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET Identify = &amp;amp;j;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test_&amp;amp; Identify;&lt;/P&gt;&lt;P&gt;Set test_&amp;amp;Identify;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;It was running fine until here, then when &amp;nbsp;introduced&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(distinct(weeks)) into :r&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from iter1_&amp;amp;Identify ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let r = &amp;amp;r;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select distinct weeks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :t1 - :t&amp;amp;r.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from iter1_&amp;amp;Identify ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%let r = &amp;amp;r;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i = &lt;STRONG&gt;1&lt;/STRONG&gt; %to &amp;amp;r;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET ctr_wk = &amp;amp;&amp;amp;t&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test_&amp;amp;ctr_wk;&lt;/P&gt;&lt;P&gt;Set test;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%assign;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference R not resolved.&lt;/P&gt;&lt;P&gt;ERROR: The text expression &amp;amp;R contains a recursive reference to the macro variable R.&amp;nbsp; The macro variable will be assigned the null&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.&lt;/P&gt;&lt;P&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;/P&gt;&lt;P&gt;ERROR: The macro ASSIGN will stop executing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 20:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561588#M10614</guid>
      <dc:creator>meckarthik</dc:creator>
      <dc:date>2019-05-25T20:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error Apparent symbolic reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561589#M10615</link>
      <description>&lt;P&gt;In general it is probably a bad idea to take data out of your dataset and put it into a series of macro variables.&amp;nbsp; You should probably take a step back a re-think how you are doing this process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the code you posted the only way R is not defined is if the the first query returns no results.&amp;nbsp; The INTO clause of the PROC SQL SELECT statement does not create the macro variables when no observations are selected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simplify your query and solve this problem also by taking advantage of the automatic macro variable SQLOBS.&amp;nbsp; There is no need to count the number of distinct weeks in advance. If you just add the bare hyphen after the macro variable name then SAS knows you want to create a series of macro variables with numeric suffixes.&amp;nbsp; If you have a really (really) old version of SAS then put a nominal upper bound, like :t1 -:t9999 , it will only create the macro variables it needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct weeks
  into :t1 - 
  from iter1_&amp;amp;Identify 
;
%let r=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now R always have a value, even if sometimes it is zero.&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 21:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561589#M10615</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-25T21:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro error Apparent symbolic reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561790#M10640</link>
      <description>&lt;P&gt;THank you so much!&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 19:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561790#M10640</guid>
      <dc:creator>meckarthik</dc:creator>
      <dc:date>2019-05-27T19:48:15Z</dc:date>
    </item>
  </channel>
</rss>

