<?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 update in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399149#M96643</link>
    <description>&lt;P&gt;update in SQL does not behave like update in a data step. Since your subquery produces a missing value, that missing value is set. Use the coalesce() function to keep the original value if the subquery yields no result.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2017 13:16:37 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-09-27T13:16:37Z</dc:date>
    <item>
      <title>proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399146#M96642</link>
      <description>&lt;P&gt;I can not understand why the next proc sql update values missing "var1" at c1 = 2 and c2 = 2 (update key). The resulting value is missing. I expected it to remain unchanged at 20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input c1 c2 var1 var2;
datalines;
1 1 12 32
1 2 32 21
2 1 12 98
2 2 20 30
2 3 11 11
3 1 21 22
4 1 31 32
2 4 22 22
6 1 77 77

;

data tmp;
input c1 c2 var1 var2;
datalines;
1 1 999 999
1 2 888 999
2 1 999 999
;
 
proc sql;
update  a 
   set var1=(select var1 from tmp as b
		         	where a.c1=b.c1 and a.c2=b.c2)

	where a.c1 in (select c1 from  tmp) and
          a.c2 in (select c2 from  tmp) 
		  ;

quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Sep 2017 12:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399146#M96642</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2017-09-27T12:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399149#M96643</link>
      <description>&lt;P&gt;update in SQL does not behave like update in a data step. Since your subquery produces a missing value, that missing value is set. Use the coalesce() function to keep the original value if the subquery yields no result.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 13:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399149#M96643</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-27T13:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399158#M96647</link>
      <description>&lt;P&gt;I do not understand, which missing value produces the subquery? at c1 = 1, c2 = 1 --- c1 = 1, c2 = 2 --- c1 = 2, c2 = 1 there are 3 lines corresponding to the values 12,32 - 32,21 - 12 98&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 13:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399158#M96647</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2017-09-27T13:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399165#M96649</link>
      <description>&lt;P&gt;There is no observation in dataset tmp with c1=2 AND c2=2, so the subquery can't find a value for that combination, which is present in observation 4 of dataset A, where the value 20 is overwritten with the missing value from the subquery.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 13:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399165#M96649</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-27T13:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399171#M96653</link>
      <description>&lt;P&gt;ok, but all other combinations do not have values in the sub query (example for c1 = 3, c2 = 1). In these cases, however, the values of dataset A remain unchanged. Only for c1 = 2, c2 = 2 is updated to missing the value of var1&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 14:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399171#M96653</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2017-09-27T14:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399173#M96655</link>
      <description>&lt;P&gt;Because your where condition at the end of the query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where a.c1 in (select c1 from  tmp) and
          a.c2 in (select c2 from  tmp) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;prevents the update from even touching those. But you do have at least one c1=2 and one c2=2 in tmp, so the combination of c1=2 and c2=2 is updated.&lt;/P&gt;
&lt;P&gt;If you want to prevent this from happening, you best create a compound key (ie c3 = c1*100 + c2) in both datasets and join on that.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 14:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399173#M96655</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-27T14:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399522#M96775</link>
      <description>&lt;P&gt;ok I understand, thank you. but this would slow down the processing if it were large databases. Is not there a different method?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 15:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399522#M96775</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2017-09-28T15:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399535#M96777</link>
      <description>&lt;P&gt;When I know that I will need a specific derived value later, I set it when such a dataset is created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Intelligent data makes for intelligent programs.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 16:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/399535#M96777</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-28T16:04:56Z</dc:date>
    </item>
  </channel>
</rss>

