<?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 Last_Insert_id() from Proc SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Last-Insert-id-from-Proc-SQL/m-p/10611#M862</link>
    <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I'm looking for a way to store the last auto id that was inserted into a mysql database.&lt;BR /&gt;
&lt;BR /&gt;
Basically, I need to insert a new observation into a database using SAS. The obervation will get an auto id once inserted. I required this auto id for inserting another observation into a different table.&lt;BR /&gt;
&lt;BR /&gt;
I'm just wondering, I'm guessing I can only use &lt;BR /&gt;
&lt;BR /&gt;
select LAST_INSERT_ID() as id&lt;BR /&gt;
&lt;BR /&gt;
when using pass-thru sql, how am I to get this value out into the local sas when my data to be inserted is stored locally. I've got a local table in work, that I need to insert into a remote table, but I will required the auto id from one insert instance to be used for the next insert instance.&lt;BR /&gt;
&lt;BR /&gt;
Or is it possible to use pass-thru sql to read from a local table and insert data into remote table?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any help.</description>
    <pubDate>Wed, 25 Mar 2009 11:12:59 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-25T11:12:59Z</dc:date>
    <item>
      <title>Last_Insert_id() from Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-Insert-id-from-Proc-SQL/m-p/10611#M862</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I'm looking for a way to store the last auto id that was inserted into a mysql database.&lt;BR /&gt;
&lt;BR /&gt;
Basically, I need to insert a new observation into a database using SAS. The obervation will get an auto id once inserted. I required this auto id for inserting another observation into a different table.&lt;BR /&gt;
&lt;BR /&gt;
I'm just wondering, I'm guessing I can only use &lt;BR /&gt;
&lt;BR /&gt;
select LAST_INSERT_ID() as id&lt;BR /&gt;
&lt;BR /&gt;
when using pass-thru sql, how am I to get this value out into the local sas when my data to be inserted is stored locally. I've got a local table in work, that I need to insert into a remote table, but I will required the auto id from one insert instance to be used for the next insert instance.&lt;BR /&gt;
&lt;BR /&gt;
Or is it possible to use pass-thru sql to read from a local table and insert data into remote table?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any help.</description>
      <pubDate>Wed, 25 Mar 2009 11:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-Insert-id-from-Proc-SQL/m-p/10611#M862</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-25T11:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Last_Insert_id() from Proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-Insert-id-from-Proc-SQL/m-p/10612#M863</link>
      <description>If you don't find another solution, then try this rather ugly hack &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL; &lt;BR /&gt;
&lt;BR /&gt;
connect to ODBC as mssql(noprompt="DRIVER=SQL Server;Server=SQLserver;DATABASE=SQLdatabase");&lt;BR /&gt;
&lt;BR /&gt;
execute ( INSERT INTO dbo.DWtable (status) VALUES ('text') ) by mssql; &lt;BR /&gt;
&lt;BR /&gt;
execute ( create table #temp (TempTableField int)) by mssql; &lt;BR /&gt;
&lt;BR /&gt;
execute ( INSERT INTO #temp SELECT IDENT_CURRENT('dbo.DWtable')) by mssql; &lt;BR /&gt;
&lt;BR /&gt;
create table temp as select * from connection to mssql (select max(TempTableField) as max from #temp);&lt;BR /&gt;
&lt;BR /&gt;
disconnect from mssql; &lt;BR /&gt;
&lt;BR /&gt;
QUIT;</description>
      <pubDate>Wed, 25 Mar 2009 13:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-Insert-id-from-Proc-SQL/m-p/10612#M863</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-03-25T13:35:46Z</dc:date>
    </item>
  </channel>
</rss>

