<?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: merging two datasets and possibly two columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-merging-two-datasets-and-possibly-two-columns/m-p/876164#M346196</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have1;
if _n_ = 1
then do;
  length result $8;
  declare hash h2 (dataset:"have2 (rename=(c2=result))");
  h2.definekey("c1");
  h2.definedata("result");
  h2.definedone();
end;
c1 = coalescec(c1,c2);
if  h2.find() ne 0 then result = "";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2023 04:40:33 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-05-17T04:40:33Z</dc:date>
    <item>
      <title>Proc sql: merging two datasets and possibly two columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-merging-two-datasets-and-possibly-two-columns/m-p/876159#M346195</link>
      <description>&lt;P&gt;I am trying to merge two datasets. The issue is the first dataset has missing values in column c1, if missing c1 then merge with c2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have1;&lt;BR /&gt;input ID c1 $ c2 $;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;datalines;&lt;BR /&gt;1 A A&lt;BR /&gt;2 B &lt;BR /&gt;3 C &lt;BR /&gt;4 . E &lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have2;&lt;BR /&gt;input c1 $ c2 $;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;datalines;&lt;BR /&gt;A AA&lt;BR /&gt;B BB&lt;BR /&gt;C CC&lt;BR /&gt;D DD&lt;BR /&gt;E EE &lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input ID c1 $ result $;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;datalines;&lt;BR /&gt;1 A AA&lt;BR /&gt;2 B BB&lt;BR /&gt;3 C CC&lt;BR /&gt;4 E EE &lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 03:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-merging-two-datasets-and-possibly-two-columns/m-p/876159#M346195</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2023-05-17T03:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: merging two datasets and possibly two columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-merging-two-datasets-and-possibly-two-columns/m-p/876164#M346196</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have1;
if _n_ = 1
then do;
  length result $8;
  declare hash h2 (dataset:"have2 (rename=(c2=result))");
  h2.definekey("c1");
  h2.definedata("result");
  h2.definedone();
end;
c1 = coalescec(c1,c2);
if  h2.find() ne 0 then result = "";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 04:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-merging-two-datasets-and-possibly-two-columns/m-p/876164#M346196</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-17T04:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql: merging two datasets and possibly two columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-merging-two-datasets-and-possibly-two-columns/m-p/876172#M346199</link>
      <description>&lt;P&gt;SQL version:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as
		select id, coalesce(have1.c1, have1.c2) as c1, have2.c2 as result
		from have1
		left join have2
		on coalesce(have1.c1, have1.c2) = have2.c1
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Small remark, since c1 is declared as char, the &amp;lt;.&amp;gt; is stored as a period, not as MISSING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 11:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-merging-two-datasets-and-possibly-two-columns/m-p/876172#M346199</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-05-17T11:50:07Z</dc:date>
    </item>
  </channel>
</rss>

