<?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: Fuzzy Matching with Dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393938#M94900</link>
    <description>&lt;P&gt;Hello Doc_Duke,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This macro is for matching cases to control and does this by individual usubjid's. I would need to match the same usubjid&amp;nbsp;in each dataset and then fuzzy match the dates (each row) to the closest matching date within 5 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will google search for matching macros, thank you for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Sep 2017 15:53:07 GMT</pubDate>
    <dc:creator>daszlosek</dc:creator>
    <dc:date>2017-09-07T15:53:07Z</dc:date>
    <item>
      <title>Fuzzy Matching with Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393878#M94888</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to fuzzy match dates that are within 5 days of each other, one data set has records that are much earlier. I was thinking I could subtract each date from have1 by each date from&amp;nbsp;have2 to find the best match.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have1&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
    INFILE DATALINES DLM='#';
    input usubjid $ date mmddyy10. data1_flag;
	FORMAT date mmddyy10.;
    datalines;
Z26-C64 #2/16/2017 #1
Z26-C64 #3/25/2017 #1
Z26-C64 #6/02/2017 #1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;have2&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have2;
    INFILE DATALINES DLM='#';
    input usubjid $ date mmddyy10. data12flag;
	FORMAT date mmddyy10.;
    datalines;
Z26-C64 #2/02/2017 #1
Z26-C64 #2/15/2017 #1
Z26-C64 #3/25/2017 #1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;want&lt;/P&gt;
&lt;TABLE width="775"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="135"&gt;usubjid&lt;/TD&gt;
&lt;TD width="95"&gt;date&lt;/TD&gt;
&lt;TD width="107"&gt;data1_flag&lt;/TD&gt;
&lt;TD width="139"&gt;data2_flag&lt;/TD&gt;
&lt;TD width="102"&gt;Date_have2&lt;/TD&gt;
&lt;TD width="133"&gt;Date_have1&lt;/TD&gt;
&lt;TD width="64"&gt;Date_Diff&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Z26-C64&lt;/TD&gt;
&lt;TD&gt;2/2/2017&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2/02/2017&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Z26-C64&lt;/TD&gt;
&lt;TD&gt;2/15/2017&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2/15/2017&lt;/TD&gt;
&lt;TD&gt;2/16/2017&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Z26-C64&lt;/TD&gt;
&lt;TD&gt;3/25/2017&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3/25/2017&lt;/TD&gt;
&lt;TD&gt;3/25/2017&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Z26-C64&lt;/TD&gt;
&lt;TD&gt;6/2/2017&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;6/2/2017&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: I believe I need to clarify that I am trying to do this for each unique_id. The case above is for a single unique_id (defined as usubjid).&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 15:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393878#M94888</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2017-09-07T15:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Fuzzy Matching with Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393895#M94894</link>
      <description>&lt;P&gt;There are a bunch of SAS macros that have been published to do this.&amp;nbsp; I did a google search&lt;/P&gt;
&lt;P&gt;matching macro sas&lt;/P&gt;
&lt;P&gt;and got a bundh.&amp;nbsp; This one looks like it will do the trick&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings10/061-2010.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings10/061-2010.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doc Muhlbaier&lt;/P&gt;
&lt;P&gt;Duke&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 14:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393895#M94894</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2017-09-07T14:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Fuzzy Matching with Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393922#M94898</link>
      <description>&lt;P&gt;Each record of HAVE1 is compared with each record of HAVE2. Are you interested any difference of 5 days, then uncomment&lt;/P&gt;
&lt;P&gt;the statement. Presently, the LOG gives the individual difference.&lt;/P&gt;
&lt;P&gt;Hope this is acceptable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
   set have1 end = eof;
      do p = 1 to num;
         set have2 (rename = (date=date2)) nobs = num point = p;

         d = abs(date - date2);
         put date = date2 = d =;

/*          if d &amp;lt; 5 then output; */
      end;
   if eof then stop;
run;

The LOG:

date=02/16/2017 date2=02/02/2017 d=14
 date=02/16/2017 date2=02/15/2017 d=1
 date=02/16/2017 date2=03/25/2017 d=37
 date=03/25/2017 date2=02/02/2017 d=51
 date=03/25/2017 date2=02/15/2017 d=38
 date=03/25/2017 date2=03/25/2017 d=0
 date=06/02/2017 date2=02/02/2017 d=120
 date=06/02/2017 date2=02/15/2017 d=107
 date=06/02/2017 date2=03/25/2017 d=69&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2017 15:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393922#M94898</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-09-07T15:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Fuzzy Matching with Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393938#M94900</link>
      <description>&lt;P&gt;Hello Doc_Duke,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This macro is for matching cases to control and does this by individual usubjid's. I would need to match the same usubjid&amp;nbsp;in each dataset and then fuzzy match the dates (each row) to the closest matching date within 5 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will google search for matching macros, thank you for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 15:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393938#M94900</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2017-09-07T15:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Fuzzy Matching with Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393940#M94901</link>
      <description>Hello Datasp,&lt;BR /&gt;&lt;BR /&gt;This is close to what I am looking for, I am trying to tweak it so it does by for matching unique ids between the two datasets (unique_Id = usubjid). If you have any hints that would be helpful!&lt;BR /&gt;&lt;BR /&gt;Best</description>
      <pubDate>Thu, 07 Sep 2017 15:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393940#M94901</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2017-09-07T15:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Fuzzy Matching with Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393957#M94902</link>
      <description>&lt;P&gt;I have added another subject and worked with BY Group. Both the datasets are to be sorted for this code to work.&lt;/P&gt;
&lt;P&gt;If this does not work for you, better place some data with 2 or more subjects. Show the required output too.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
    INFILE DATALINES DLM='#';
    input usubjid $ date mmddyy10. data1_flag;
   FORMAT date mmddyy10.;
    datalines;
Z26-C64 #2/16/2017 #1
Z26-C64 #3/25/2017 #1
Z26-C64 #6/02/2017 #1
Z28-C65 #6/06/2017 #2
Z28-C65 #7/25/2017 #2
;
run;
 


data have2;
    INFILE DATALINES DLM='#';
    input usubjid $ date mmddyy10. data12flag;
   FORMAT date mmddyy10.;
    datalines;
Z26-C64 #2/02/2017 #1
Z26-C64 #2/15/2017 #1
Z26-C64 #3/25/2017 #1
Z28-C65 #6/02/2017 #2
Z28-C65 #7/02/2017 #2
Z28-C65 #7/22/2017 #2
;
run;

proc sort data = have1;
by usubjid;
run;

proc sort data = have2;
by usubjid;
run;

data need;
   set have1 (rename = (usubjid = id)) end = eof;
      do p = 1 to num;
         set have2 (rename = (date=date2)) nobs = num point = p;
         if usubjid = id then do;
            d = abs(date - date2);
            put id = usubjid = date = date2 = d =;

         if d &amp;lt; 5 then output;
         end;
         else continue;
      end;
      put '===========================';
   if eof then stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2017 16:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fuzzy-Matching-with-Dates/m-p/393957#M94902</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-09-07T16:45:46Z</dc:date>
    </item>
  </channel>
</rss>

