<?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 find the shortest distance between terms within text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376399#M276603</link>
    <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For unknown reason, my OP was deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will post my question here again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if I have a table below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;text &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;term&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABCAB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABCAB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to find the shortest distance between terms within same ID.&lt;/P&gt;
&lt;P&gt;P.S same ID would have same text&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: in the first record I have ID=1 text=ABC &amp;nbsp;term=A , in the second record I have ID=1 text=ABC and term=B&lt;/P&gt;
&lt;P&gt;I want to compare A with A, and A with B, and B with B for ID=1&lt;/P&gt;
&lt;P&gt;the position of first A is&amp;nbsp;1, the second A has a position of 4 so the distance between A with A is 4-1=3&lt;/P&gt;
&lt;P&gt;the position of first A is 1, the first B has a position=2, the second B has a position=5&lt;/P&gt;
&lt;P&gt;so the distance between first A with first B is 2-1=1 and the distance between first A with second B is 5-1=4 so shortest distance between A with B is 1&lt;/P&gt;
&lt;P&gt;the position of second A is 4, the position of first B is 2 so the distance is 2-4=-2,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the position of second A is 4, the position of second B is 5 so the distance is 5-4=1&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so the final table should look like:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; term1 &amp;nbsp; term2 &amp;nbsp; shortest distance&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jul 2017 01:27:31 GMT</pubDate>
    <dc:creator>gyambqt</dc:creator>
    <dc:date>2017-07-18T01:27:31Z</dc:date>
    <item>
      <title>find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376399#M276603</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For unknown reason, my OP was deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will post my question here again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if I have a table below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;text &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;term&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABCAB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABCAB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to find the shortest distance between terms within same ID.&lt;/P&gt;
&lt;P&gt;P.S same ID would have same text&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: in the first record I have ID=1 text=ABC &amp;nbsp;term=A , in the second record I have ID=1 text=ABC and term=B&lt;/P&gt;
&lt;P&gt;I want to compare A with A, and A with B, and B with B for ID=1&lt;/P&gt;
&lt;P&gt;the position of first A is&amp;nbsp;1, the second A has a position of 4 so the distance between A with A is 4-1=3&lt;/P&gt;
&lt;P&gt;the position of first A is 1, the first B has a position=2, the second B has a position=5&lt;/P&gt;
&lt;P&gt;so the distance between first A with first B is 2-1=1 and the distance between first A with second B is 5-1=4 so shortest distance between A with B is 1&lt;/P&gt;
&lt;P&gt;the position of second A is 4, the position of first B is 2 so the distance is 2-4=-2,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the position of second A is 4, the position of second B is 5 so the distance is 5-4=1&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so the final table should look like:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; term1 &amp;nbsp; term2 &amp;nbsp; shortest distance&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 01:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376399#M276603</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2017-07-18T01:27:31Z</dc:date>
    </item>
    <item>
      <title>Find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376418#M276605</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For unknown reason, my OP was deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will post my question here again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if I have a table below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;text &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;term&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABCAB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABCAB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to find the shortest distance between terms within same ID.&lt;/P&gt;
&lt;P&gt;P.S same ID would have same text&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: in the first record I have ID=1 text=ABC &amp;nbsp;term=A , in the second record I have ID=1 text=ABC and term=B&lt;/P&gt;
&lt;P&gt;I want to compare A with A, and A with B, and B with B for ID=1&lt;/P&gt;
&lt;P&gt;the position of first A is&amp;nbsp;1, the second A has a position of 4 so the distance between A with A is 4-1=3&lt;/P&gt;
&lt;P&gt;the position of first A is 1, the first B has a position=2, the second B has a position=5&lt;/P&gt;
&lt;P&gt;so the distance between first A with first B is 2-1=1 and the distance between first A with second B is 5-1=4 so shortest distance between A with B is 1&lt;/P&gt;
&lt;P&gt;the position of second A is 4, the position of first B is 2 so the distance is 2-4=-2,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the position of second A is 4, the position of second B is 5 so the distance is 5-4=1&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so the final table should look like:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; term1 &amp;nbsp; term2 &amp;nbsp; shortest distance&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 06:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376418#M276605</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2017-07-17T06:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376420#M276606</link>
      <description>&lt;P&gt;Your original post is still there: &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376399" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376399&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 06:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376420#M276606</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-17T06:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376421#M276607</link>
      <description>&lt;P&gt;Ah...I received a message saying that post was deleted...&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 06:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376421#M276607</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2017-07-17T06:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376429#M276608</link>
      <description>&lt;P&gt;Right, well your post is quite confusing, and do remember to post test data in the form of a datastep in future. &amp;nbsp;This shold start you off:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id text $ term $;
datalines;
1 ABCAB A
1 ABCAB B
;
run;

data want;
  set have;
  do i=1 to lengthn(text);
    dist=999;
    do j=i to lengthn(text);
      if char(text,i)=char(text,j) and j-i &amp;lt; dist then dist=j-1;
    end;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;So you see you can loop over a string, which is just an array of characters.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 08:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376429#M276608</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-17T08:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376808#M276609</link>
      <description>&lt;P&gt;sorry for the confusion, I have modified the question in accordance to my other post (same question). I hope this helps to clarify.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 23:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376808#M276609</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2017-07-17T23:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376838#M276610</link>
      <description>&lt;P&gt;How is the B-B distance 1?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 01:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376838#M276610</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-18T01:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376839#M276611</link>
      <description>&lt;P&gt;sorry it was typo.....it is fixed now!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 01:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376839#M276611</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2017-07-18T01:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376841#M276612</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input ID TEXT $ TERM $;
cards;
1 ABCAB A
1 ABCAB B
run;
data WANT;
  retain TERMS;
  length TERMS $80;
  set HAVE;
  by ID;
  if first.ID then TERMS='';
  if not findw(TERMS,trim(TERM)) then TERMS=catx(' ', TERMS, TERM); 
  if last.ID then do I=1 to countw(TERMS,' ');
    do J=1 to countw(TERMS,' ');
      TERM1 =scan(TERMS, I);
      TERM2 =scan(TERMS, J);
      DIST  =1e9;
      POS1  =0 ;
      do until(POS1=0|POS2=0);
        POS1=find(TEXT,trim(TERM1),POS1+1);  
        POS2=find(TEXT,trim(TERM2),POS1+1);  
        if POS1 &amp;amp; POS2 then DIST=min(DIST,POS2-POS1);
      end;
      output;
    end; 
  end; 
run;  
proc print noobs;
  var ID TERM1 TERM2 DIST;
run; 
     
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;ID&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;TERM1&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;TERM2&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;DIST&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;A&lt;/TD&gt;
&lt;TD class="b data"&gt;A&lt;/TD&gt;
&lt;TD class="b data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;A&lt;/TD&gt;
&lt;TD class="b data"&gt;B&lt;/TD&gt;
&lt;TD class="b data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;B&lt;/TD&gt;
&lt;TD class="b data"&gt;A&lt;/TD&gt;
&lt;TD class="b data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b data"&gt;1&lt;/TD&gt;
&lt;TD class="b data"&gt;B&lt;/TD&gt;
&lt;TD class="b data"&gt;B&lt;/TD&gt;
&lt;TD class="b data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 01:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376841#M276612</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-18T01:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376851#M276613</link>
      <description>&lt;P&gt;Hi thanks for your prompt reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the shorted distance between A and B or B and A should be same both =1&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 03:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376851#M276613</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2017-07-18T03:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376855#M276614</link>
      <description>&lt;P&gt;I think I got you close enough.&lt;/P&gt;
&lt;P&gt;Just do a quick post-processing step if needed.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 03:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376855#M276614</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-18T03:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376867#M276615</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HI I realise there is a small issue with the code and I modified below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; terms;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; terms $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;32767&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; troy;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; source_key_value1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first.source_key_value1 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; terms=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; findw(terms,trim(upcase(term))) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; terms=catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, upcase(terms), upcase(term));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; last.source_key_value1 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; to countw(upcase(upcase(terms)),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; j=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; countw(upcase(terms),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;term1 =scan(upcase(terms), i);&lt;/P&gt;
&lt;P&gt;term2 =scan(upcase(terms), j);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; dist =&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;999999&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; pos1 =&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; pos2 =&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;until&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(pos1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; or pos2=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; pos1=find(compress(msg1),trim(upcase(term1)),pos1+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; upcase(term1)=upcase(term2) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;pos2=pos1;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; pos2=find(compress(msg1),trim(upcase(term2)),pos2+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; pos1 &amp;amp; pos2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;dist=min(dist,abs(pos2-pos1));&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 05:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/376867#M276615</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2017-07-18T05:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/377140#M276616</link>
      <description>&lt;P&gt;There are no issues with the code and it did axactly what you requested.&lt;/P&gt;
&lt;P&gt;If you have length and case to take into account, use the find() function's modifiers: &amp;nbsp;find(V1,V2,'it') -rather than upcase() and compress() and trim()- to make more legible code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/377140#M276616</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-18T21:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: find the shortest distance between terms within text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/377675#M276617</link>
      <description>Will there ever be more than two terms for an ID?&lt;BR /&gt;Is there a text length limit?  Is it 5 characters or more?&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Jul 2017 08:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-shortest-distance-between-terms-within-text/m-p/377675#M276617</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-07-20T08:41:29Z</dc:date>
    </item>
  </channel>
</rss>

