<?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: proc sql connect to odbc - how to insert records in sql table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/544885#M150697</link>
    <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63211"&gt;@bmillson1&lt;/a&gt;&lt;BR /&gt;you need to talk to your SQL Server DBA(s) and have them both update that password - admin(?!) - and grant you insert privileges either on that tableX or the whole "forking" schema. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; (:</description>
    <pubDate>Thu, 21 Mar 2019 14:53:19 GMT</pubDate>
    <dc:creator>ccaulkins9</dc:creator>
    <dc:date>2019-03-21T14:53:19Z</dc:date>
    <item>
      <title>proc sql connect to odbc - how to insert records in sql table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/543870#M150364</link>
      <description>&lt;P&gt;proc sql;&lt;BR /&gt;connect to ODBC as mycon (datasrc='DB');&lt;/P&gt;&lt;P&gt;EXECUTE (SET IDENTITY_INSERT tableX ON ) by mycon;&lt;BR /&gt;INSERT INTO tableX (id,name,city)&lt;BR /&gt;SELECT (id,name,city) FROM work.tableY;&lt;/P&gt;&lt;P&gt;EXECUTE (SET IDENTITY_INSERT tableX OFF ) by mycon;&lt;BR /&gt;disconnect from mycon;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- DB is a sql database reference via odbc&lt;/P&gt;&lt;P&gt;- tableX is an existing table in the sql database&lt;/P&gt;&lt;P&gt;- id is a primary key&lt;/P&gt;&lt;P&gt;- work.tableY is a temp dataset in SAS that I want to use to update tableX in sql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code runs with no errors, but the problem is it creates a temp dataset in SAS as work.tableX.&amp;nbsp; I want it to insert the records in tableX in sql.&amp;nbsp; Clearly I'm missing a step that defines tableX as a table in sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 05:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/543870#M150364</guid>
      <dc:creator>bmillson1</dc:creator>
      <dc:date>2019-03-18T05:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql connect to odbc - how to insert records in sql table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/543879#M150365</link>
      <description>&lt;P&gt;You can't use SQL passthru to load a SAS table into an external database as the SQL runs purely in that database and knows nothing about SAS tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A good way to solve this problem is to use PROC DATASETS with a LIBNAME assigned to the external database:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname MyODBC ODBC noprompt = '&amp;lt;put your ODBC connection string here&amp;gt;';

proc datasets library = MyODBC;
  append base = tableX data = work.tableY;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Mar 2019 07:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/543879#M150365</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-18T07:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql connect to odbc - how to insert records in sql table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/543882#M150367</link>
      <description>&lt;P&gt;Since you do not use a reference to the ODBC connection in the important part of the SQL, it is equivalent to just this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
INSERT INTO tableX (id,name,city)
SELECT (id,name,city) FROM work.tableY;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to define a library connection to the SQL Server and use that in the INSERT INTO clause.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 07:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/543882#M150367</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-18T07:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql connect to odbc - how to insert records in sql table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/544002#M150406</link>
      <description>&lt;P&gt;Thanks for the quick replies!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I add the reference to the sql table using libname, I get an error. I've confirmed the libname process works as I can do other tasks successfully. What I ultimately need to achieve is adding the id,name,city to v.tableX (from work.tableY). Wondering if part of the issue is that id is a primary key? Either way, I need to insert the id from work.tableY as it's from a prod db and affects mappings to other tables. So I don't want to the use the libname option of&amp;nbsp;ignore_read_only_columns=yes, as the id's aren't sequential. That's why I'm trying to use&amp;nbsp;IDENTITY_INSERT, plus the insert code, in the single proc sql.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname v odbc dsn=DB user=sa pwd=admin schema=dbo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;connect to ODBC as mycon (datasrc='DB');&lt;/P&gt;&lt;P&gt;EXECUTE (SET IDENTITY_INSERT v.tableX ON ) by mycon;&lt;BR /&gt;INSERT INTO v.tableX (id,name,city)&lt;BR /&gt;SELECT (id,name,city) FROM work.tableY;&lt;/P&gt;&lt;P&gt;EXECUTE (SET IDENTITY_INSERT v.tableX OFF ) by mycon;&lt;BR /&gt;disconnect from mycon;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: CLI execute error: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find the object "v.tableX" because it does &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;not exist or you do not have permissions.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 15:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/544002#M150406</guid>
      <dc:creator>bmillson1</dc:creator>
      <dc:date>2019-03-18T15:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql connect to odbc - how to insert records in sql table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/544447#M150570</link>
      <description>&lt;P&gt;Sorry, I don't follow you argument of why not to use the libname.&lt;/P&gt;
&lt;P&gt;Perhaps you can try to use the libname, see what happens. Either it proves your point (which is?), or showed that it's actually working for your use case.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 06:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/544447#M150570</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2019-03-20T06:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql connect to odbc - how to insert records in sql table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/544885#M150697</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63211"&gt;@bmillson1&lt;/a&gt;&lt;BR /&gt;you need to talk to your SQL Server DBA(s) and have them both update that password - admin(?!) - and grant you insert privileges either on that tableX or the whole "forking" schema. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; (:</description>
      <pubDate>Thu, 21 Mar 2019 14:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-connect-to-odbc-how-to-insert-records-in-sql-table/m-p/544885#M150697</guid>
      <dc:creator>ccaulkins9</dc:creator>
      <dc:date>2019-03-21T14:53:19Z</dc:date>
    </item>
  </channel>
</rss>

