<?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 Proc Sql + Left Join - Overwrite values of existing variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-Overwrite-values-of-existing-variables/m-p/433081#M107339</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found many threads on this question with solutions using merge. I understand why proc sql is doing what it does but I want to know if there is&amp;nbsp;elegant way to left join with proc sql and for the rows with matching keys overwrite the value of a variable in the left table with the one from the right (the variable exists in both tables with the same name).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE&gt;data test1;
input id age ;
datalines;
1 25 
2 26 
3 27 
;

data test2;
input id age ;
datalines;
2 100 
;

proc sql;
	create table test3 as
	select a.*, b.age
	from test1 a 
	left join test2 b
	on a.id=b.id;
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The resulting output is:&lt;/P&gt;&lt;P&gt;id age&lt;/P&gt;&lt;P&gt;1&amp;nbsp;25&lt;BR /&gt;2&amp;nbsp;26&lt;BR /&gt;3&amp;nbsp;27&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired output is:&lt;/P&gt;&lt;P&gt;1&amp;nbsp;25&lt;BR /&gt;2&amp;nbsp;100&lt;BR /&gt;3&amp;nbsp;27&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 12:31:13 GMT</pubDate>
    <dc:creator>KonstantinVasil</dc:creator>
    <dc:date>2018-02-01T12:31:13Z</dc:date>
    <item>
      <title>Proc Sql + Left Join - Overwrite values of existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-Overwrite-values-of-existing-variables/m-p/433081#M107339</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found many threads on this question with solutions using merge. I understand why proc sql is doing what it does but I want to know if there is&amp;nbsp;elegant way to left join with proc sql and for the rows with matching keys overwrite the value of a variable in the left table with the one from the right (the variable exists in both tables with the same name).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE&gt;data test1;
input id age ;
datalines;
1 25 
2 26 
3 27 
;

data test2;
input id age ;
datalines;
2 100 
;

proc sql;
	create table test3 as
	select a.*, b.age
	from test1 a 
	left join test2 b
	on a.id=b.id;
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The resulting output is:&lt;/P&gt;&lt;P&gt;id age&lt;/P&gt;&lt;P&gt;1&amp;nbsp;25&lt;BR /&gt;2&amp;nbsp;26&lt;BR /&gt;3&amp;nbsp;27&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired output is:&lt;/P&gt;&lt;P&gt;1&amp;nbsp;25&lt;BR /&gt;2&amp;nbsp;100&lt;BR /&gt;3&amp;nbsp;27&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 12:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-Overwrite-values-of-existing-variables/m-p/433081#M107339</guid>
      <dc:creator>KonstantinVasil</dc:creator>
      <dc:date>2018-02-01T12:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql + Left Join - Overwrite values of existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-Overwrite-values-of-existing-variables/m-p/433086#M107341</link>
      <description>&lt;P&gt;I think&amp;nbsp;the COALESCE function&amp;nbsp;does what you want:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
      create table test3 as
      select
        test1.id,
        coalesce(test2.age,test1.age) as age
      from test1
      left join test2
      on test1.id=test2.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 12:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-Overwrite-values-of-existing-variables/m-p/433086#M107341</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-02-01T12:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql + Left Join - Overwrite values of existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-Overwrite-values-of-existing-variables/m-p/433087#M107342</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
input id age ;
datalines;
1 25 
2 26 
3 27 
;

data test2;
input id age ;
datalines;
2 100 
;

proc sql;
	create table test3 as
	select a.id,ifn(b.age ne ., b.age, a.age) as age 
	from test1 a 
	left join test2 b
	on a.id=b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 12:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-Overwrite-values-of-existing-variables/m-p/433087#M107342</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-01T12:51:51Z</dc:date>
    </item>
  </channel>
</rss>

