<?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: Updating a table with corresponding values in a second table with Proc SQl in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321047#M313483</link>
    <description>&lt;P&gt;You can use the coalesce function, which takes the first non-missing value from a list of values.&amp;nbsp; The list in this case is "b.value,a.value", as below.&amp;nbsp; In other words, a.value is kept only when b.value is missing or absent:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Sasfont"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;table&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; want &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; &amp;nbsp; select&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; coalesce(b.value,a.value) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;as&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; value, * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; a &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;join&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; b &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;on&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; a.id=b.id;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 24 Dec 2016 18:53:32 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2016-12-24T18:53:32Z</dc:date>
    <item>
      <title>Updating a table with corresponding values in a second table with Proc SQl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/320928#M313479</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to update the variable from one dataset with another variable from second dataset, I have tried Proc SQL update command. but couldn't able to get it, I'm a beginner in proc sql. &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 data sets with 2 variables in it,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATASET_A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; Value&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;23&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 11&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 98&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 54&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;30&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; 44&lt;/P&gt;&lt;P&gt;DATASET_B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; Value&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 54&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to update the values of DATASET_A with DATASET_B. So the desired output will be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; Value&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 54&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 54&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 54&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; 44&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried with the code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;update DATASET_A&amp;nbsp;&lt;BR /&gt;set value=(select value from DATASET_B &amp;nbsp;where &lt;SPAN&gt;DATASET_A&amp;nbsp;&lt;/SPAN&gt;.value=&lt;SPAN&gt;DATASET_B&lt;/SPAN&gt;.value)&lt;BR /&gt;where ID in (select ID from &lt;SPAN&gt;DATASET_B&lt;/SPAN&gt;);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its giving me "&lt;SPAN&gt; ERROR: Subquery evaluated to more than one row." &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;what does it mean? Any help?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 14:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/320928#M313479</guid>
      <dc:creator>JithinJoe</dc:creator>
      <dc:date>2016-12-23T14:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Updating a table with corresponding values in a second table with Proc SQl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321003#M313480</link>
      <description>&lt;P&gt;As long as you are a beginner using SQL, let's use a different but very common SAS tool.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge dataset_a (in=in1) dataset_b (in=in2 rename=(value=value_from_b));&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if in1;&lt;/P&gt;
&lt;P&gt;if in2 then value = value_from_b;&lt;/P&gt;
&lt;P&gt;drop value_from_b;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program relies on the data being in sorted order. &amp;nbsp;If that's not the case, you'll have to sort first.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 20:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321003#M313480</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-23T20:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Updating a table with corresponding values in a second table with Proc SQl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321013#M313481</link>
      <description>&lt;P&gt;For Proc SQL here an example with explanation how this needs to look like with the SAS SQL flavour.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/25/216.html" target="_blank"&gt;http://support.sas.com/kb/25/216.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Dec 2016 00:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321013#M313481</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-12-24T00:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Updating a table with corresponding values in a second table with Proc SQl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321020#M313482</link>
      <description>&lt;PRE&gt;
It should be A.ID=B.ID.


data DATASET_A;
input ID   Value;
cards;
1      10
1      11
1      23
2     11
2     98
2     54
3    10
3    30
4   44
;

data DATASET_B;
input ID   Value;
cards;
1      25
2     54
3    13
;

proc sql;
update DATASET_A 
set value=(select value from DATASET_B  where DATASET_A.id=DATASET_B.id)
where ID in (select ID from DATASET_B);
quit;
 

&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Dec 2016 04:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321020#M313482</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-24T04:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Updating a table with corresponding values in a second table with Proc SQl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321047#M313483</link>
      <description>&lt;P&gt;You can use the coalesce function, which takes the first non-missing value from a list of values.&amp;nbsp; The list in this case is "b.value,a.value", as below.&amp;nbsp; In other words, a.value is kept only when b.value is missing or absent:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Sasfont"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;table&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; want &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; &amp;nbsp; select&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; coalesce(b.value,a.value) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;as&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; value, * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; a &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;join&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; b &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;on&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; a.id=b.id;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Dec 2016 18:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-a-table-with-corresponding-values-in-a-second-table/m-p/321047#M313483</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-24T18:53:32Z</dc:date>
    </item>
  </channel>
</rss>

