<?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 Faster way to write a SQL Update Query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166222#M32032</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a more efficient way to write this SQL Update Query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It has to be an update, not a table overwrite, though the update can be through SQL or a data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UPDATE TABLE1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET&amp;nbsp;&amp;nbsp; VAR1 = (select P.VAR1 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR2 = (select P.VAR2 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR3 = (select P.VAR3 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR4 = (select P.VAR4 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR5 = (select P.VAR5 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Aug 2014 21:24:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2014-08-18T21:24:11Z</dc:date>
    <item>
      <title>Faster way to write a SQL Update Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166222#M32032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a more efficient way to write this SQL Update Query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It has to be an update, not a table overwrite, though the update can be through SQL or a data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UPDATE TABLE1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET&amp;nbsp;&amp;nbsp; VAR1 = (select P.VAR1 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR2 = (select P.VAR2 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR3 = (select P.VAR3 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR4 = (select P.VAR4 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , VAR5 = (select P.VAR5 from TABLE2 as P where P.GROUP = I.GROUP and P.NUM = &amp;amp;ID)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 21:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166222#M32032</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-08-18T21:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to write a SQL Update Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166223#M32033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use the SAS UPDATE statement &lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/67407/HTML/default/viewer.htm#p18w3br45er2qun1r8sfmm4grjyr.htm" title="http://support.sas.com/documentation/cdl/en/lestmtsref/67407/HTML/default/viewer.htm#p18w3br45er2qun1r8sfmm4grjyr.htm"&gt;SAS(R) 9.4 Statements: Reference, Third Edition&lt;/A&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;You could load "table2" into a hash table, look-up the values and if there is a match to the hash replace the record using a SAS MODIFY statement with REPLACE (this way no sorting of table1 required).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;For your SQL: You could subset table2 (where NUM=&amp;amp;ID) before using it in your sub-selects&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 23:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166223#M32033</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-08-18T23:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to write a SQL Update Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166224#M32034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look into using the MODIFY statement.&lt;/P&gt;&lt;P&gt;Look at Example 3 in this help document.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n0g9jfr4x5hgsfn17gtma5547lt1.htm" style="font-size: 10pt; line-height: 1.5em;" title="http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n0g9jfr4x5hgsfn17gtma5547lt1.htm"&gt;SAS(R) 9.3 Statements: Reference&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Aug 2014 02:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166224#M32034</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-08-19T02:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to write a SQL Update Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166225#M32035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Tom, MODIFY is usually the fastest way to do updates, given that the transaction table is relatively small.&lt;/P&gt;&lt;P&gt;If you wish do keep the SQL, be sure to have proper indexes (on both master and transaction tables), it could speed things up.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Aug 2014 10:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Faster-way-to-write-a-SQL-Update-Query/m-p/166225#M32035</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-08-19T10:28:31Z</dc:date>
    </item>
  </channel>
</rss>

