<?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: Match table A string with Table B keyword in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835111#M41467</link>
    <description>&lt;P&gt;Ok. What if a string in table a matches multiple substrings in table b?&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2022 07:01:19 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-09-26T07:01:19Z</dc:date>
    <item>
      <title>Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835108#M41464</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New to SAS, need some help in string matching. I have Table A which have millions of records. Table B has less than 5K records.&lt;/P&gt;&lt;P&gt;I want to match Address field of table A with Keywords field of table B. Currently doing Proc SQL with Like operation which is very slow and query takes ages. There is a cross join between both the tables. Both tables are in SAS.&lt;/P&gt;&lt;P&gt;Wanted to know the efficient way of doing this. Using SAS EG V 8.2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will be a great help. Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS Data.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75558i872D7D3E9ABD1455/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS Data.PNG" alt="SAS Data.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 06:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835108#M41464</guid>
      <dc:creator>cheema11</dc:creator>
      <dc:date>2022-09-26T06:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835109#M41465</link>
      <description>&lt;P&gt;Are these both SAS Data Sets?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 06:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835109#M41465</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-26T06:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835110#M41466</link>
      <description>Yes both are sas data sets.</description>
      <pubDate>Mon, 26 Sep 2022 06:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835110#M41466</guid>
      <dc:creator>cheema11</dc:creator>
      <dc:date>2022-09-26T06:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835111#M41467</link>
      <description>&lt;P&gt;Ok. What if a string in table a matches multiple substrings in table b?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 07:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835111#M41467</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-26T07:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835112#M41468</link>
      <description>Return the one with longest string length. If string length is same, then return any one of them.</description>
      <pubDate>Mon, 26 Sep 2022 07:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835112#M41468</guid>
      <dc:creator>cheema11</dc:creator>
      <dc:date>2022-09-26T07:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835113#M41469</link>
      <description>&lt;P&gt;The longest string from table b, right?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 07:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835113#M41469</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-26T07:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835115#M41470</link>
      <description>Yes longest string from Table B</description>
      <pubDate>Mon, 26 Sep 2022 07:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835115#M41470</guid>
      <dc:creator>cheema11</dc:creator>
      <dc:date>2022-09-26T07:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835121#M41471</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;for asking all the questions.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434820"&gt;@cheema11&lt;/a&gt;&amp;nbsp;Please provide next time sample data via a working SAS data step so we don't have to spend time to create such data in order to provide tested code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe below should do what you're asking for. It's still a resource intensive process but certainly better than a cartesian join.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master;
  id=_n_;
  infile datalines truncover;
  input address $40.;
  datalines;
alias_address: abc@swy.com.au
alias_address: pa@baxa.com
alias_address: baxa@test.com
alias_address: 123456789@baxa.com
;

data lookup;
  infile datalines truncover;
  input keyword $ category $;
  datalines;
A swy
A baxa
B 12345678
C test
;

data lookup;
  set lookup;
  _str_len=length(category);
run;

proc sort data=lookup;
  by descending _str_len;
run;

data want(drop=_:);
  set master;
  _r_len=-1;
  do _i=1 to _nobs;
    set lookup point=_i nobs=_nobs;
    if _r_len&amp;gt;_str_len then leave;
    if find(address,category,'it') then
      do;
        output;
        _r_len=_str_len;
      end;
  end;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1664184308051.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75560i0A5A29554AB75D8D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1664184308051.png" alt="Patrick_0-1664184308051.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 09:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835121#M41471</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-26T09:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835355#M41473</link>
      <description>Thanks for the response on this. Really appreciate for the help. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;</description>
      <pubDate>Tue, 27 Sep 2022 02:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/835355#M41473</guid>
      <dc:creator>cheema11</dc:creator>
      <dc:date>2022-09-27T02:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/836448#M41498</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;.&lt;BR /&gt;In response to your query...."What if a string in table A matches multiple substrings in table B?" My answer was "Return the one with longest string length in Table B. If string length is same, then return any one of them."&lt;BR /&gt;&lt;BR /&gt;What do i need to change in the script if I want to return the string with shortest length in Table B?</description>
      <pubDate>Mon, 03 Oct 2022 00:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/836448#M41498</guid>
      <dc:creator>cheema11</dc:creator>
      <dc:date>2022-10-03T00:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Match table A string with Table B keyword</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/836473#M41499</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434820"&gt;@cheema11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;.&lt;BR /&gt;In response to your query...."What if a string in table A matches multiple substrings in table B?" My answer was "Return the one with longest string length in Table B. If string length is same, then return any one of them."&lt;BR /&gt;&lt;BR /&gt;What do i need to change in the script if I want to return the string with shortest length in Table B?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;did all the work getting the full requirements from you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1664781929579.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75812i5E4A0EA010B77F75/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1664781929579.png" alt="Patrick_0-1664781929579.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 07:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Match-table-A-string-with-Table-B-keyword/m-p/836473#M41499</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-10-03T07:26:28Z</dc:date>
    </item>
  </channel>
</rss>

