<?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: Problems with Merging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427439#M105412</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
infile datalines dlm='/';
input (Date  Share_ID Fund Value) ($);
datalines;
Mar2012/ 123 / A / 5$
Apr2012 / 124 / B / 6$
;

data table2;
infile datalines dlm='/';
input (Date  Share_ID Fund Value) ($);
datalines;
Mar2012/ 123 / C / 6$
Aug2012 / 124 / B / 6$
;

proc sql;
create table want as
 select *
  from table1
union all
 select * 
  from table2
   where catx(' ',date,share_id) not in 
   (select catx(' ',date,share_id) from table1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 13 Jan 2018 10:19:37 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-01-13T10:19:37Z</dc:date>
    <item>
      <title>Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427408#M105389</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im a student from Germany and having some problems with merging two tables at the moment. I hope someone of you can help me with that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; The problem is:&lt;/P&gt;&lt;P&gt;I have two tables, each of those 2 tables has the following structure:&lt;/P&gt;&lt;P&gt;(Let´s say, this is Table 1)&lt;/P&gt;&lt;P&gt;Date / Share-ID, Fund, Value&lt;/P&gt;&lt;P&gt;Mar2012/ 123 / A / 5$&lt;/P&gt;&lt;P&gt;Apr2012 / 124 / B / 6$&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, the first row can be understood as: In March 2012, Fund A valued the Share-ID 123 with 5$.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, let´s say Table 2 looks like this:&lt;/P&gt;&lt;P&gt;Date / Share-ID, Fund, Value&lt;/P&gt;&lt;P&gt;Mar2012/ 123 /&amp;nbsp;C / 6$&lt;/P&gt;&lt;P&gt;Aug2012 / 124 / B / 6$&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, what I want now is this table:&lt;/P&gt;&lt;P&gt;Date / Share-ID, Fund, Value&lt;/P&gt;&lt;P&gt;Mar2012/ 123 / A / 5$&lt;/P&gt;&lt;P&gt;Apr2012 / 124 / B / 6$&lt;/P&gt;&lt;P&gt;Aug2012 / 124 / B / 6$&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That means, I want to have all different DATE-SHAREID Combinations of both tables, but always take the one from Table 1 if it´s not missing. Or in other words, I only want to add a row from Table 2 to Table 1, if the Date-ShareID combination is not in Table 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already could solve this problem by using a Full Join, with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table&amp;nbsp;dest as select&lt;BR /&gt;coalesce(a.shareid, b.shareid) as shareid,&lt;BR /&gt;coalesce(a.date, b.date) as date,&lt;BR /&gt;a.value as value,&lt;BR /&gt;b.value as newValue,&lt;BR /&gt;coalesce(a.fundid, b.fundid) as fundid&lt;BR /&gt;from work.table1 as a full join&lt;BR /&gt;work.table2 as b&lt;BR /&gt;on (a.shareID = b.shareID and a.date = b.date);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.dest;&lt;BR /&gt;set work.dest;&lt;BR /&gt;if missing(value) and not missing(newValue) then do;&lt;BR /&gt;value = newValue;&lt;BR /&gt;end;&lt;BR /&gt;drop newValue;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, the performance of this program is so bad, that I cant run it on my PC (It´s a Macro, so the program runs at least 1000 times).&lt;/P&gt;&lt;P&gt;I´d really appreciate if someone could provide a smarter solution of this problem &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance and sorry for my bad English.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Zlatan&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 02:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427408#M105389</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-01-13T02:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427415#M105395</link>
      <description>&lt;P&gt;Have you looked into either UPDATE or MODIFY Statements?&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 03:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427415#M105395</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-13T03:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427417#M105396</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/186452"&gt;@mrzlatan91&lt;/a&gt;, You wrote - &lt;EM&gt;"Unfortunately, the performance of this program is so bad, that I cant run it on my PC (It´s a Macro, so the program runs at least 1000 times)."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Where is the macro and why macro?&lt;/P&gt;&lt;P&gt;2. Should i give you a hash solution, are you ok with it?&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 04:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427417#M105396</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-13T04:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427428#M105405</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
infile datalines dlm='/';
input (Date  Share_ID Fund Value) ($);
datalines;
Mar2012/ 123 / A / 5$
Apr2012 / 124 / B / 6$
;

data table2;
infile datalines dlm='/';
input (Date  Share_ID Fund Value) ($);
datalines;
Mar2012/ 123 / C / 6$
Aug2012 / 124 / B / 6$
;

data want;
   if _N_ = 1 then do;
   if 0 then set table2;
      declare hash h(dataset:'table2');
      h.defineKey('share_id','date');
      h.defineData(all:'yes');
      h.defineDone();
	  declare hiter iter('h');
      end;
	  set table1 end=last;
	  if h.check()= 0 then h.remove();
	  output;
	  if last then   rc = iter.first();
   do while (rc = 0);
      output;
      rc = iter.next();
   end;
   drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Jan 2018 06:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427428#M105405</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-13T06:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427435#M105410</link>
      <description>&lt;P&gt;Dear navinosrin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much, this is exactly what I wanted to have.&lt;/P&gt;&lt;P&gt;Im using a Macro, because I need to do SQL-Operations and Data-Steps as long&amp;nbsp;&lt;/P&gt;&lt;P&gt;as a specific condition is valid.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you ever come to Germany, you´ll get as much beer as you can drink &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice weekend.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 09:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427435#M105410</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-01-13T09:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427439#M105412</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
infile datalines dlm='/';
input (Date  Share_ID Fund Value) ($);
datalines;
Mar2012/ 123 / A / 5$
Apr2012 / 124 / B / 6$
;

data table2;
infile datalines dlm='/';
input (Date  Share_ID Fund Value) ($);
datalines;
Mar2012/ 123 / C / 6$
Aug2012 / 124 / B / 6$
;

proc sql;
create table want as
 select *
  from table1
union all
 select * 
  from table2
   where catx(' ',date,share_id) not in 
   (select catx(' ',date,share_id) from table1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Jan 2018 10:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427439#M105412</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-13T10:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427454#M105421</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/186452"&gt;@mrzlatan91&lt;/a&gt;&amp;nbsp;I would like that offer. My favorite is indeed dunkel&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;dark German lager &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Ok, if you are satisfied, kindly mark the question as answered and close the thread.&amp;nbsp; You have a good weekend too. Take care!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 17:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427454#M105421</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-13T17:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427468#M105430</link>
      <description>Good choice dude. You can also try Munich „Helles“ from Hacker Pschorr (he invented this sort of beer). Yeah I marked it as „solved“. Thanks again&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: thanks for your additional solution</description>
      <pubDate>Sat, 13 Jan 2018 20:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-Merging/m-p/427468#M105430</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-01-13T20:39:15Z</dc:date>
    </item>
  </channel>
</rss>

