<?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 Error using macro variable in table column name in inner join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-using-macro-variable-in-table-column-name-in-inner-join/m-p/849680#M335876</link>
    <description>&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am fairly new to SAS.&lt;/P&gt;&lt;P&gt;I'm trying to use an inner join to match unique identifiers in two tables. I have made a macro variable in which I can change the year, drug code and name I am interested in. I get an error and it seems to be because there is a macro variable in the table name. I am stuck as to figuring out a workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro prevusers(year, code, substance) ;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create table file1.a&amp;amp;year&amp;amp;substance as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select distinct ID1, ID2 from file1.pop1 inner join file1.subs_list&amp;amp;year&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on pop1.ID1=subs_list&amp;amp;year.ID2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where code like "&amp;amp;code";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%mend prevusers;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%prevusers (1995, J01%, antibio)&lt;/P&gt;&lt;P&gt;%prevusers (1996, J01%, antibio)&lt;/P&gt;&lt;P&gt;%prevusers (1997, J01%, antibio)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error states: "The following columns were not found in the contributing tables: subs_list1995ID2."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apparently it interprets&amp;nbsp;subs_list&amp;amp;year.ID2 as a column name and ignores the dot separating the table name and column name. Any ideas as to how this issue can be resolved?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2022 16:01:39 GMT</pubDate>
    <dc:creator>ha33</dc:creator>
    <dc:date>2022-12-14T16:01:39Z</dc:date>
    <item>
      <title>Error using macro variable in table column name in inner join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-macro-variable-in-table-column-name-in-inner-join/m-p/849680#M335876</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am fairly new to SAS.&lt;/P&gt;&lt;P&gt;I'm trying to use an inner join to match unique identifiers in two tables. I have made a macro variable in which I can change the year, drug code and name I am interested in. I get an error and it seems to be because there is a macro variable in the table name. I am stuck as to figuring out a workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro prevusers(year, code, substance) ;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create table file1.a&amp;amp;year&amp;amp;substance as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select distinct ID1, ID2 from file1.pop1 inner join file1.subs_list&amp;amp;year&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on pop1.ID1=subs_list&amp;amp;year.ID2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where code like "&amp;amp;code";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%mend prevusers;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%prevusers (1995, J01%, antibio)&lt;/P&gt;&lt;P&gt;%prevusers (1996, J01%, antibio)&lt;/P&gt;&lt;P&gt;%prevusers (1997, J01%, antibio)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error states: "The following columns were not found in the contributing tables: subs_list1995ID2."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apparently it interprets&amp;nbsp;subs_list&amp;amp;year.ID2 as a column name and ignores the dot separating the table name and column name. Any ideas as to how this issue can be resolved?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 16:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-macro-variable-in-table-column-name-in-inner-join/m-p/849680#M335876</guid>
      <dc:creator>ha33</dc:creator>
      <dc:date>2022-12-14T16:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Error using macro variable in table column name in inner join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-macro-variable-in-table-column-name-in-inner-join/m-p/849691#M335880</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need another dot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;subs_list&amp;amp;year..ID2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the macro language if you do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let foo=foo;
%put &amp;amp;foobar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro language will look for macro variable named foobar, which doesn't exist.&amp;nbsp; You use a dot to tell the macro processor that the name of the macro variable has ended.&amp;nbsp; So if you want a dot in your code, you need two dots, .e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    %let foo=foo;
2    %put &amp;amp;foobar;
WARNING: Apparent symbolic reference FOOBAR not resolved.
&amp;amp;foobar
3    %put &amp;amp;foo.bar ;
foobar
4    %put &amp;amp;foo..bar ;
foo.bar
&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 16:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-macro-variable-in-table-column-name-in-inner-join/m-p/849691#M335880</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-12-14T16:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Error using macro variable in table column name in inner join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-macro-variable-in-table-column-name-in-inner-join/m-p/849810#M335920</link>
      <description>Thanks a lot! Works perfectly now.</description>
      <pubDate>Thu, 15 Dec 2022 09:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-macro-variable-in-table-column-name-in-inner-join/m-p/849810#M335920</guid>
      <dc:creator>ha33</dc:creator>
      <dc:date>2022-12-15T09:01:05Z</dc:date>
    </item>
  </channel>
</rss>

