<?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: Matching data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404131#M98238</link>
    <description>Thank you so much for your prompt reply!!&lt;BR /&gt;I really appreciate it.&lt;BR /&gt;It works!</description>
    <pubDate>Fri, 13 Oct 2017 20:42:49 GMT</pubDate>
    <dc:creator>ursula</dc:creator>
    <dc:date>2017-10-13T20:42:49Z</dc:date>
    <item>
      <title>Matching data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404099#M98231</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This dataset I named it as "Matching file"&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; Age&amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp;C&lt;/P&gt;
&lt;P&gt;M1&amp;nbsp; 20&amp;nbsp; 10&amp;nbsp; &amp;nbsp;Yes&amp;nbsp; &amp;nbsp;No&lt;BR /&gt;M2&amp;nbsp; 25&amp;nbsp; 12&amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;M3&amp;nbsp; 30&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; Yes&amp;nbsp; Yes&lt;BR /&gt;M4&amp;nbsp; 40&amp;nbsp; &amp;nbsp;50&amp;nbsp; Yes&amp;nbsp; Yes&lt;BR /&gt;M5&amp;nbsp; 50&amp;nbsp; &amp;nbsp;25&amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp;No&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This dataset I named it as "Searching file"&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Age&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;
&lt;P&gt;A100&amp;nbsp; &amp;nbsp; &amp;nbsp; 25&amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; Yes&amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp;-------------------matching M1&lt;BR /&gt;A200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; Yes&amp;nbsp; &amp;nbsp;Yes --------------------matching M3&lt;BR /&gt;A300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; No&amp;nbsp; &amp;nbsp;Yes ---------------------matching M2&lt;BR /&gt;A400&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;35&amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp;Yes ---------------------No matching&lt;BR /&gt;A500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp; &amp;nbsp; 30&amp;nbsp; &amp;nbsp;Yes&amp;nbsp; Yes ---------------------No matching&lt;BR /&gt;A600&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp;Yes&amp;nbsp; Yes ---------------------matching M4&lt;BR /&gt;A700&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;35&amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp;Yes&amp;nbsp; Yes ----------------------matching M4&lt;BR /&gt;A800&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&amp;nbsp; &amp;nbsp; &amp;nbsp; 25&amp;nbsp; &amp;nbsp;Yes&amp;nbsp; &amp;nbsp;No ----------------------No matching&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to search for which IDs in "Searching file" are matching with the IDs in "Matching file", the &lt;STRONG&gt;Age&lt;/STRONG&gt; can be +/- 5&amp;nbsp;from the "matching file", but&amp;nbsp;the variables A,B and C have to exactly the same value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is: how do I code it in SAS so I can output the Matching data, as follow:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I want:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;
&lt;P&gt;A100&amp;nbsp; &amp;nbsp;25&amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; Yes&amp;nbsp; &amp;nbsp;No&lt;BR /&gt;A200&amp;nbsp; &amp;nbsp;25&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;A300&amp;nbsp; &amp;nbsp;30&amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; No&amp;nbsp; &amp;nbsp;Yes&lt;BR /&gt;A600&amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp; &amp;nbsp;50&amp;nbsp; &amp;nbsp; Yes&amp;nbsp; Yes&lt;BR /&gt;A700&amp;nbsp; &amp;nbsp;35&amp;nbsp; &amp;nbsp; &amp;nbsp;50&amp;nbsp; &amp;nbsp; Yes&amp;nbsp; Yes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 19:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404099#M98231</guid>
      <dc:creator>ursula</dc:creator>
      <dc:date>2017-10-13T19:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Matching data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404108#M98234</link>
      <description>&lt;P&gt;This could be one way.&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table want as
   select  a.*
   from Searchfile as a
        left join
        Matchingfile as b
        on  a.a = b.a
        and a.b = b.b
        and a.c = b.c
   where abs(a.age-b.age) le 5;
quit;&lt;/PRE&gt;
&lt;P&gt;Searchfile and Matchingfile should be your actual dataset names. The notation involving the a. and b. are shorthand for Searchfile.a meaning the variable a in the data set Searchfile. The "as a" assigns the shortcut name, it isn't magical what they should be as long as you keep them straight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logic is to match all of the a, b and c variable and then keep the record where the difference in the ages is &amp;lt;= to 5. If you haven't used Proc SQL the QUIT is used instead of Run to indicate the end of the procedure.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 20:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404108#M98234</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-13T20:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Matching data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404114#M98235</link>
      <description>&lt;P&gt;DATA MATCHING;&lt;/P&gt;&lt;P&gt;INFILE DATALINES;&lt;BR /&gt;INPUT ID_MTCH :$ Age_MTCH: 8. A :8. B :$8. C :$8.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;M1 20 10 Yes No&lt;BR /&gt;M2 25 12 No Yes&lt;BR /&gt;M3 30 5 Yes Yes&lt;BR /&gt;M4 40 50 Yes Yes&lt;BR /&gt;M5 50 25 No No&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;DATA Searching;&lt;BR /&gt;INFILE DATALINES;&lt;BR /&gt;INPUT ID :$ Age: 8. A :8. B :$8. C :$8.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;A100 25 10 Yes No&lt;BR /&gt;A200 25 5 Yes Yes&lt;BR /&gt;A300 30 12 No Yes&lt;BR /&gt;A400 35 12 No Yes&lt;BR /&gt;A500 40 30 Yes Yes&lt;BR /&gt;A600 40 50 Yes Yes&lt;BR /&gt;A700 35 50 Yes Yes&lt;BR /&gt;A800 50 25 Yes No&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=matching;&lt;BR /&gt;by A B C;&lt;BR /&gt;proc sort data=searching;&lt;BR /&gt;BY A B C;&lt;BR /&gt;DATA WANT(KEEP=ID Age A B C) ;&lt;BR /&gt;MERGE MATCHING(in=match) Searching(IN=search);&lt;BR /&gt;BY A B C;&lt;BR /&gt;IF MATCH=1 and search=1 and ABS(age_mtch-age)&amp;lt;=5;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 23:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404114#M98235</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-10-13T23:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Matching data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404131#M98238</link>
      <description>Thank you so much for your prompt reply!!&lt;BR /&gt;I really appreciate it.&lt;BR /&gt;It works!</description>
      <pubDate>Fri, 13 Oct 2017 20:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404131#M98238</guid>
      <dc:creator>ursula</dc:creator>
      <dc:date>2017-10-13T20:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Matching data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404132#M98239</link>
      <description>&lt;P&gt;Thanks so much for the codes!&lt;/P&gt;
&lt;P&gt;I like it and it works!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 20:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-data/m-p/404132#M98239</guid>
      <dc:creator>ursula</dc:creator>
      <dc:date>2017-10-13T20:44:30Z</dc:date>
    </item>
  </channel>
</rss>

