<?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: Insert into confusion in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138781#M37235</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Thanks. These are both great options.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Mar 2014 13:13:57 GMT</pubDate>
    <dc:creator>tmm</dc:creator>
    <dc:date>2014-03-11T13:13:57Z</dc:date>
    <item>
      <title>Insert into confusion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138777#M37231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I am a little confused with my insert into code. I have 2 datasets and want to keep all of the first dataset and only move those records in the second dataset that are not in the first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;insert&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; first a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; second b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; not &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;exists&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; first a &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; a.strata=b.strata);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 19:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138777#M37231</guid>
      <dc:creator>tmm</dc:creator>
      <dc:date>2014-03-10T19:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into confusion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138778#M37232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think&amp;nbsp; your where condition is incorrect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One way to test results before proceeding is to select first and then once you have that working, insert.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ie. Get this part working first:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; * &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; second b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; not &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;exists&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; first a &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; a.strata=b.strata);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 19:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138778#M37232</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-03-10T19:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into confusion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138779#M37233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The where works when I run that alone, it is when adding the insert to that I get an error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You cannot reopen first for update access with member-level control because first is in use by you in resource environment SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that means that since the table exists in my library that I cannot insert into it if using it in this query. So, I bet Ihave to select the records that where not exist and then append to first. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 20:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138779#M37233</guid>
      <dc:creator>tmm</dc:creator>
      <dc:date>2014-03-10T20:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into confusion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138780#M37234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, I don't think you can subquery a table which is already being processed.&amp;nbsp; Try a join and coalesce (which takes first non-nul value):&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as &lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; COALESCE(A.STRATA,B.STRATA) as STRATA&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; FIRST A&lt;/P&gt;&lt;P&gt;&amp;nbsp; full join SECOND B&lt;/P&gt;&lt;P&gt;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.STRATA=B.STRATA;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Alternatively you could adopt a two step approach such as:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table TMP as&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; *&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; SECOND&lt;BR /&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; STRATA not in (select distinct STRATA from FIRST);&lt;BR /&gt;&amp;nbsp; insert into FIRST&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; *&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; TMP;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Mar 2014 10:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138780#M37234</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-03-11T10:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Insert into confusion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138781#M37235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Thanks. These are both great options.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Mar 2014 13:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Insert-into-confusion/m-p/138781#M37235</guid>
      <dc:creator>tmm</dc:creator>
      <dc:date>2014-03-11T13:13:57Z</dc:date>
    </item>
  </channel>
</rss>

