<?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: No observations using SAS macro ole db connection in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795344#M255102</link>
    <description>&lt;P&gt;The second method worked. Thank you so much!&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 21:26:58 GMT</pubDate>
    <dc:creator>lapetitemaman</dc:creator>
    <dc:date>2022-02-09T21:26:58Z</dc:date>
    <item>
      <title>No observations using SAS macro ole db connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795326#M255088</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to pull some data from an internal database through OLE DB connection using a SAS macro. Below is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro list(Form, name);&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;connect to oledb (init="Provider=xxxxx; Password=xxxxx; Persist Security Info=True; Usder ID=xxxx; Initial Catalog=xxxx; Data Source=xxx");&lt;/P&gt;&lt;P&gt;create table &amp;amp;Form as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select * from connection to oledb(&lt;/P&gt;&lt;P&gt;select distinct(t1.Item)&lt;/P&gt;&lt;P&gt;from Table1 as t1&lt;/P&gt;&lt;P&gt;cross join Table2 as t2&lt;/P&gt;&lt;P&gt;where t1.ID=t2.ID and t2.exam_version='&amp;amp;name'&lt;/P&gt;&lt;P&gt;group by t1.Item;);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%mend list;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%list(Form1,Math_TC1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code ran but resulted in 0 observations with no error message. However, if I replaced the &amp;amp;name in the macro with the actual name (i.e., Math_TC1), the code would run correctly. Any pointers what the issue may be and how to modify my code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795326#M255088</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-02-09T20:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: No observations using SAS macro ole db connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795332#M255092</link>
      <description>&lt;P&gt;Macro variables do not resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;So in this&lt;/P&gt;
&lt;PRE&gt;where t1.ID=t2.ID and t2.exam_version='&amp;amp;name'&lt;/PRE&gt;
&lt;P&gt;the comparison was to the literal value &amp;amp;name which would almost certainly not appear in your data.&lt;/P&gt;
&lt;P&gt;try&lt;/P&gt;
&lt;PRE&gt;where t1.ID=t2.ID and t2.exam_version="&amp;amp;name"&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795332#M255092</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-09T20:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: No observations using SAS macro ole db connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795334#M255094</link>
      <description>&lt;P&gt;I have tried to use double quotes instead of single quotes and received an error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Describe error: IColumnsInfo::GetColumnInfo failed. : Deferred prepare could not be&lt;BR /&gt;completed.: Statement(s) could not be prepared.: Invalid column name 'xxx'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 21:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795334#M255094</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-02-09T21:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: No observations using SAS macro ole db connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795338#M255097</link>
      <description>&lt;P&gt;maybe try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where t1.ID=t2.ID and t2.exam_version=%str(%')&amp;amp;name%str(%')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could refactor it to pass the quotes in the value for NAME when you call the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list(Form, name);

proc sql;
connect to oledb (init="Provider=xxxxx; Password=xxxxx; Persist Security Info=True; Usder ID=xxxx; Initial Catalog=xxxx; Data Source=xxx");
create table &amp;amp;Form as 
select * from connection to oledb(
select distinct(t1.Item)
from Table1 as t1
cross join Table2 as t2
where t1.ID=t2.ID and t2.exam_version=&amp;amp;name   /*no quotes here*/
group by t1.Item;);
quit;

%mend list;

%list(Form1,'Math_TC1')  /*added quotes here*/&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 21:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795338#M255097</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-02-09T21:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: No observations using SAS macro ole db connection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795344#M255102</link>
      <description>&lt;P&gt;The second method worked. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 21:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-observations-using-SAS-macro-ole-db-connection/m-p/795344#M255102</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-02-09T21:26:58Z</dc:date>
    </item>
  </channel>
</rss>

