<?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: find the Neighbouring Repetitive Words in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593568#M170363</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;appreciate for your&amp;nbsp;remind.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to get both of them if it happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;just like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;name&lt;/TD&gt;&lt;TD&gt;repeat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;APPLE LTD LTD INC INC&lt;/TD&gt;&lt;TD&gt;LTD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;APPLE LTD LTD INC INC&lt;/TD&gt;&lt;TD&gt;INC&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me some suggestions about this?&lt;/P&gt;&lt;P&gt;thanks a lot.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Oct 2019 22:39:25 GMT</pubDate>
    <dc:creator>Alexxxxxxx</dc:creator>
    <dc:date>2019-10-02T22:39:25Z</dc:date>
    <item>
      <title>find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593552#M170355</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to find the&amp;nbsp;Neighbouring Repetitive Words？and get the repeated word.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, for the table 'have'&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;APPLE LTD LTD 
USA Australia Japan USA
FOOTBALL LTD FOOTBALL LP&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;APPLE LTD LTD |&amp;nbsp;LTD&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Because it has an 'LTD LTD' which are together and are the same words. and then I would like to get a new variable which lists the word. in this example is ‘LTD'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;USA Australia Japan USA
FOOTBALL LTD FOOTBALL LP&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;should not be extracted. although they have the same words they are not together.&lt;/P&gt;&lt;P&gt;Could you please give me some suggestion about this? Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string :$200.;
infile datalines dlm=',';
string=upcase(string);
datalines;
APPLE LTD LTD 
USA Australia Japan USA
FOOTBALL LTD FOOTBALL LP
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 21:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593552#M170355</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-10-02T21:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593554#M170357</link>
      <description>How much data are you working with?&lt;BR /&gt;I usually recommend splitting the data to individual words and then doing the analysis which is easier. &lt;BR /&gt;&lt;BR /&gt;*Create sample data;&lt;BR /&gt;data random_sentences;&lt;BR /&gt;    infile cards truncover;&lt;BR /&gt;    informat sentence $256.;&lt;BR /&gt;    input sentence $256.;&lt;BR /&gt;    cards;&lt;BR /&gt;This is a random sentence&lt;BR /&gt;This is another random sentence&lt;BR /&gt;Happy Birthday&lt;BR /&gt;My job sucks.&lt;BR /&gt;This is a good idea, not.&lt;BR /&gt;This is an awesome idea!&lt;BR /&gt;How are you today?&lt;BR /&gt;Does this make sense?&lt;BR /&gt;Have a great day!&lt;BR /&gt;;&lt;BR /&gt;    ;&lt;BR /&gt;    ;&lt;BR /&gt;    ;&lt;BR /&gt;&lt;BR /&gt;*Partition into words;&lt;BR /&gt;data f1;&lt;BR /&gt;    set random_sentences;&lt;BR /&gt;    id=_n_;&lt;BR /&gt;    nwords=countw(sentence);&lt;BR /&gt;    nchar=length(compress(sentence));&lt;BR /&gt;&lt;BR /&gt;    do word_order=1 to nwords;&lt;BR /&gt;        word=scan(sentence, word_order);&lt;BR /&gt;        output;&lt;BR /&gt;    end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/text_analysis.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/text_analysis.sas&lt;/A&gt;</description>
      <pubDate>Wed, 02 Oct 2019 21:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593554#M170357</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-02T21:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593556#M170358</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; Are you expecting to have just one set of repeating words in the string or more. If more, what would the result look like?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 21:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593556#M170358</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-02T21:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593558#M170359</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for the table&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;name&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;APPLE LTD LTD&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;USA Australia Japan USA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FOOTBALL LTD FOOTBALL LP&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to get&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;name&lt;/TD&gt;&lt;TD&gt;repeat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;APPLE LTD LTD&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;LTD&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 02 Oct 2019 21:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593558#M170359</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-10-02T21:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593559#M170360</link>
      <description>&lt;P&gt;I understood that. That is as simple as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input string :$200.;
infile datalines dlm=',';
string=upcase(string);
datalines;
APPLE LTD LTD 
USA Australia Japan USA
FOOTBALL LTD FOOTBALL LP
;
run;

data want;
set have;
do _n_=2 to countw(string,' ');
 if scan(string,_n_,' ')=scan(string,_n_-1,' ') then want=scan(string,_n_,' ');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My question though is what if there are more one set of repeating words.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;/P&gt;
&lt;P&gt;APPLE LTD LTD INC INC&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 21:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593559#M170360</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-02T21:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593568#M170363</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;appreciate for your&amp;nbsp;remind.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to get both of them if it happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;just like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;name&lt;/TD&gt;&lt;TD&gt;repeat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;APPLE LTD LTD INC INC&lt;/TD&gt;&lt;TD&gt;LTD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;APPLE LTD LTD INC INC&lt;/TD&gt;&lt;TD&gt;INC&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me some suggestions about this?&lt;/P&gt;&lt;P&gt;thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 22:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593568#M170363</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-10-02T22:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593575#M170366</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some fun stuff&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input string :$200.;
infile datalines dlm=',';
string=upcase(string);
datalines;
APPLE LTD LTD 
USA Australia Japan USA
FOOTBALL LTD FOOTBALL LP
APPLE LTD LTD INC INC
;
run;

data want;
if _n_ then do;
   dcl hash H () ;
   h.definekey  ("repeat") ;
   h.definedata ("repeat") ;
   h.definedone () ;
   dcl hiter hi('h');
 end;
set have;
do _n_=2 to countw(string,' ');
 if scan(string,_n_,' ')=scan(string,_n_-1,' ') then do;
 repeat= scan(string,_n_,' ');
 h.replace();
 end;
end;
do while(hi.next()=0);
 output;
end;
h.clear();
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 00:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593575#M170366</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-03T00:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593603#M170383</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                               
  input @1 str &amp;amp; $upcase30. ;                                             
  cards ;                                                                 
APPLE LTD LTD                                                             
USA Australia Japan USA                                                   
FOOTBALL LTD FOOTBALL LP                                                  
APPLE LTD LTD INC INC                                                     
;                                                                         
run ;                                                                     
                                                                          
data want (drop = _:) ;                                                   
  set have ;                                                              
  length _s $ 32767 repeat $ 30 ;                                         
  do _x = 1 to countw (str) ;                                             
    repeat = scan (str, _x) ;                                             
    if repeat ne scan (str, _x + 1) or findw (_s, repeat) then continue ; 
    output ;                                                              
    _s = catx (" ", _s, repeat) ;                                         
  end ;                                                                   
run ;                                                                     
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 05:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593603#M170383</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-03T05:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: find the Neighbouring Repetitive Words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593610#M170388</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string :$200.;
infile datalines dlm=',';
string=upcase(string);
datalines;
APPLE LTD LTD 
USA Australia Japan USA
FOOTBALL LTD FOOTBALL LP
APPLE LTD LTD INC INC
;
run;

data want(drop=st s l);
    if _N_ = 1 then _iorc_=prxparse('/\b(\w+)\b\s*(\1)\b/');
    set have;
    st=string;
    do while (prxmatch(_iorc_, st));
        repeat=prxposn(_iorc_, 2, st);
        output;
        call prxposn(_iorc_, 2, s, l);
        st=substr(st, s+l+1);
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;string                  repeat
APPLE LTD LTD	        LTD
APPLE LTD LTD INC INC	LTD
APPLE LTD LTD INC INC	INC&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 06:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-Neighbouring-Repetitive-Words/m-p/593610#M170388</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-03T06:38:04Z</dc:date>
    </item>
  </channel>
</rss>

