<?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 Equivalent in SQL of Update statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-SQL-of-Update-statement/m-p/802445#M315899</link>
    <description>&lt;P&gt;I have this code :&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data want ; update have result ; /* updates table have with table result values */&amp;nbsp;
by var ;&amp;nbsp;
run ;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;i would like to know the equivalent way to do this with proc SQL in order to avoid the proc sort step before the data step.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Mar 2022 10:22:38 GMT</pubDate>
    <dc:creator>elsfy</dc:creator>
    <dc:date>2022-03-16T10:22:38Z</dc:date>
    <item>
      <title>Equivalent in SQL of Update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-SQL-of-Update-statement/m-p/802445#M315899</link>
      <description>&lt;P&gt;I have this code :&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data want ; update have result ; /* updates table have with table result values */&amp;nbsp;
by var ;&amp;nbsp;
run ;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;i would like to know the equivalent way to do this with proc SQL in order to avoid the proc sort step before the data step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 10:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-SQL-of-Update-statement/m-p/802445#M315899</guid>
      <dc:creator>elsfy</dc:creator>
      <dc:date>2022-03-16T10:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent in SQL of Update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-SQL-of-Update-statement/m-p/802447#M315901</link>
      <description>&lt;P&gt;Surely you realize that SQL still has to do a sort in order to do the update. You just don't have to program it in SAS.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 10:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-SQL-of-Update-statement/m-p/802447#M315901</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-16T10:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent in SQL of Update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-SQL-of-Update-statement/m-p/802479#M315922</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;that&amp;nbsp;SQL needs to do a sort under the hood.&amp;nbsp; It may be a bit more efficient than PROC SORT because the sorting only generates utility files (or maybe even just memory objects) rather than making a complete SAS dataset file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But consider the far more wordy code needed to replicate the UPDATE statement, which only replaces a value from HAVE with a value from RESULT when the new value is not missing.&amp;nbsp; As far as I know, this means coding explicit COALESCE (or COALESCEC) functions for each variable that is present in both datasets.&amp;nbsp; For example, when you have a one-to-one join, you would need to do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input id  a b c;
datalines;
1  11 111 1111
2  .  222 2222
3  33  .  3333
run;
data RESULT;
input id a b c ;
datalines;
1 -11 -111 -1111 
2 -22 -222 -2222
3  .  -333 -3333
run;

proc sql;
  create table ljoin as
  select coalesce(h.a,r.a) as a, coalesce(h.b,r.b) as b, coalesce(h.c,r.c) as c
  from HAVE as h left join RESULT as r on h.id=r.id;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the above wouldn't replicate UPDATE for a one-to-many join (UPDATE would generate only 1 record per by-group).&amp;nbsp; I leave it to those more expert in SQL to show how that would be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point is there is far more coding required to avoid a preliminary PROC SORT when replicating UPDATE.&amp;nbsp; I'm not even sure it can be done, because the UPDATE statement depends on the within-bygroup order of incoming RESULT records.&amp;nbsp; SQL makes no commitment to honor such record order.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 15:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-SQL-of-Update-statement/m-p/802479#M315922</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-16T15:09:19Z</dc:date>
    </item>
  </channel>
</rss>

