<?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: Merging with multiple, incomplet by variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347439#M80257</link>
    <description>&lt;P&gt;Thank you so much for offering this up. It's kind of intimidating, so I went with the SQL solution offered up by PGStats. It seems to work. With much respect though I ask, do you think your solution offers capabilities that that simple SQL solution does not? I'm sure you would agree that simple is better, but not if it means giving up a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;-r&lt;/P&gt;</description>
    <pubDate>Wed, 05 Apr 2017 15:37:57 GMT</pubDate>
    <dc:creator>RobVoss</dc:creator>
    <dc:date>2017-04-05T15:37:57Z</dc:date>
    <item>
      <title>Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346001#M79698</link>
      <description>&lt;P&gt;I need to merge two files of patient data, each verified to have only one row per person. Each file contains name, SSN, and MedID, but each field contains many missings and patients that don't overlap both files. I'd like to combine like this:&lt;/P&gt;&lt;P&gt;if SSN matches, then merge,&lt;/P&gt;&lt;P&gt;else if MedID matches then merge,&lt;/P&gt;&lt;P&gt;else if name matches then merge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought to do each step and save only the matches, but then when I combinded to three output datasets I'd have a lot of duplicate records, since some might match on more than one criteria.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to push the match flag (in=x) back to the original datasets? Then I could embark on step 2 while omitting those records already matched.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not new to SAS, but this really has me stumped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greatly appreciate any help that's out there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;-r&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 00:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346001#M79698</guid>
      <dc:creator>RobVoss</dc:creator>
      <dc:date>2017-03-31T00:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346011#M79705</link>
      <description>&lt;P&gt;You could use SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table merged as
select ....
from 
	set1 inner join
	set2 on set1.SSN=set2.SSN or set1.MedID=set2.MedID or set1.name=set2.name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 02:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346011#M79705</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-31T02:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346015#M79707</link>
      <description>&lt;P&gt;&lt;A href="http://www.the-link-king.com" target="_blank"&gt;http://www.the-link-king.com&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link Plus from CDC&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.cdc.gov/cancer/npcr/tools/registryplus/lp.htm" target="_blank"&gt;https://www.cdc.gov/cancer/npcr/tools/registryplus/lp.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 03:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346015#M79707</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-31T03:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346171#M79780</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/How-to-find-link-between-nodes/td-p/341819" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/How-to-find-link-between-nodes/td-p/341819&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the last post of mine at the first page.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 14:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346171#M79780</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-31T14:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346175#M79782</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data x;
input Application_ID   (Email_ID  IP_ID Address_ID phone_ID) ( :$20.);
cards;
1                            email1    ip1       address1     phone1    
2                            email2    ip2        address1    phone2
3                            email3   ip2         address2    phone5
4                            email5    ip1         address3     phone13
5                            email1  ip13       address13  phone13
11 email21 ip21 address21 phone21
12 email22 ip21 address22 phone22
13 email22 ip22 address23 phone23
;
run;

data have;
 set x;
 array x{*} $ Email_ID  IP_ID Address_ID phone_ID;
 length from to $ 100;

if cmiss(of x{*})=dim(x) then delete;
 else if cmiss(of x{*})=1 then do;
     from=coalescec(of x{*});to=uuidgen(0);output; 
 end;
  else do;

          do i=1 to dim(x)-1;
           from=x{i};
            do j=i+1 to dim(x);
             to=x{j};
             if not missing(from) and not missing(to) then output;
             end;
          end;

       end;


 keep from to;
run;




data full;
  set have end=last;
  if _n_ eq 1 then do;
   declare hash h();
    h.definekey('node');
     h.definedata('node');
     h.definedone();
  end;
  output;
  node=from; h.replace();
  from=to; to=node;
  output;
  node=from; h.replace();
  if last then h.output(dataset:'node');
  drop node;
run;


data want(keep=node household);
declare hash ha(ordered:'a');
declare hiter hi('ha');
ha.definekey('count');
ha.definedata('last');
ha.definedone();
declare hash _ha(hashexp: 20);
_ha.definekey('key');
_ha.definedone();

if 0 then set full;
declare hash from_to(dataset:'full(where=(from is not missing and to is not missing))',hashexp:20,multidata:'y');
 from_to.definekey('from');
 from_to.definedata('to');
 from_to.definedone();

if 0 then set node;
declare hash no(dataset:'node');
declare hiter hi_no('no');
 no.definekey('node');
 no.definedata('node');
 no.definedone();
 

do while(hi_no.next()=0);
 household+1; output;
 count=1;
 key=node;_ha.add();
 last=node;ha.add();
 rc=hi.first();
 do while(rc=0);
   from=last;rx=from_to.find();
   do while(rx=0);
     key=to;ry=_ha.check();
      if ry ne 0 then do;
       node=to;output;rr=no.remove(key:node);
       key=to;_ha.add();
       count+1;
       last=to;ha.add();
      end;
      rx=from_to.find_next();
   end;
   rc=hi.next();
end;
ha.clear();_ha.clear();
end;
stop;
run;

data final_want;
if _n_=1 then do;
 if 0 then set want;
 declare hash h(dataset:'want');
 h.definekey('node');
 h.definedata('household');
 h.definedone();
end;
 set x;
 array x{*} $ Email_ID  IP_ID Address_ID phone_ID;
 do i=1 to dim(x);
  node=x{i};call missing(household);
  if h.find()=0 then leave;
 end;
 drop i node;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 15:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/346175#M79782</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-31T15:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347433#M80252</link>
      <description>&lt;P&gt;Sorry to be slow with my gratitude here but, THANKS!&lt;/P&gt;&lt;P&gt;This was just the solution I needed.&lt;/P&gt;&lt;P&gt;I expanded the "ON" portion to accomodate missing values, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table m3 as
select * from h full join c 
	on (
		(h.ssn=c.ssn and c.ssn ne "")
		or
		(h.cin =c.cin and c.cin ne "")or
		(h.name =c.name and c.name ne "")
		);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm including a WORD Attachment of code that includes sample datasets in case anyone finds this later and wants to explore. Sorry I didn't include code to begin with, would have made post easier to follow.&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;rob&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347433#M80252</guid>
      <dc:creator>RobVoss</dc:creator>
      <dc:date>2017-04-05T15:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347435#M80254</link>
      <description>&lt;P&gt;thanks for these: they look very comprehensive and will probably be useful in future.&lt;/P&gt;&lt;P&gt;-r&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347435#M80254</guid>
      <dc:creator>RobVoss</dc:creator>
      <dc:date>2017-04-05T15:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347439#M80257</link>
      <description>&lt;P&gt;Thank you so much for offering this up. It's kind of intimidating, so I went with the SQL solution offered up by PGStats. It seems to work. With much respect though I ask, do you think your solution offers capabilities that that simple SQL solution does not? I'm sure you would agree that simple is better, but not if it means giving up a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;-r&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347439#M80257</guid>
      <dc:creator>RobVoss</dc:creator>
      <dc:date>2017-04-05T15:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347492#M80281</link>
      <description>&lt;P&gt;One last thought.&lt;/P&gt;&lt;P&gt;My attached code (both the inner of full joins) does result in duplicates, so beware if you try it. I'm currently trying to sort this out: learning about fuzzy matching and match scores. The big takeaway for me is that this can't be solved in a data step but the SQL join offers lots of possibilities to match on several vars sequentially while saving a measure (match scores) that can be used to rank the matches and trim down to the final result. Code by KSharp might get to this result too.&lt;/P&gt;&lt;P&gt;-r&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 19:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347492#M80281</guid>
      <dc:creator>RobVoss</dc:creator>
      <dc:date>2017-04-05T19:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with multiple, incomplet by variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347495#M80282</link>
      <description>&lt;P&gt;The difference between a SQL solution and &amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;hash solution will most likely come down to speed.&lt;/P&gt;
&lt;P&gt;The hash solution should be faster, but you trade it for code complexity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're doing this once stick with the SQL. If you need to set up a process, explore the hash solution.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 19:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-with-multiple-incomplet-by-variables/m-p/347495#M80282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-05T19:48:50Z</dc:date>
    </item>
  </channel>
</rss>

