<?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: Removing repeated substring in String/Observation from the string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/615656#M180099</link>
    <description>&lt;P&gt;The below code is sometimes excluding the&amp;nbsp; substring with a minor difference in the spelling . Tried with both FIND and FINDW but it is not excluding the exact matching word. In the below example &lt;STRONG&gt;Japan and Japanese&lt;/STRONG&gt; are two different words but when using find function JAPAN is getting excluded because of JAPANESE , similarly in the last row when both &lt;STRONG&gt;FATESTCD and FATEST&lt;/STRONG&gt; are present only FATESTCD is present , FATEST is getting excluded. Only the exact word should get removed ,but its not happening here.Any suggestions/updates on this.&lt;/P&gt;
&lt;P&gt;How can we try this using PRXMATCH,?&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=',';
datalines;
apple orange kiwi apple grapes strawberry peach kiwi peach
China USA UK Australia Japanese USA UK Australian Japan Chinase
FOOTBALL BasketBall basketball Hockey football
FACAT FATESTCD FATEST FAOBJ STDT STDTC VISIT VISITNUM
;

data want(keep=string newstring);
   set have;
   newstring=scan(string, 1, ' ');
   do i=2 to countw(string,' ');
      word=scan(string, i, ' ');
      found=find(newstring, word, 'it');&lt;BR /&gt;      *found=findw(newstring, word, 'it');;
      if found=0 then newstring=catx(' ', newstring, word);
   end;
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>Tue, 07 Jan 2020 13:24:05 GMT</pubDate>
    <dc:creator>keen_sas</dc:creator>
    <dc:date>2020-01-07T13:24:05Z</dc:date>
    <item>
      <title>Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542382#M149868</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I have repeated sub strings/duplicate words in a string . I would like to remove the repeated words from the string and &lt;BR /&gt;keep only the unique values in the string.Words are mix of cases. Any shortcut approach to do this. i am trying to do this using arrays and do loop .&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;TABLE width="667"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="389"&gt;&lt;STRONG&gt;Have&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="278"&gt;Want&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;apple orange kiwi apple grapes strawberry peach kiwi peach&lt;/TD&gt;
&lt;TD&gt;apple orange kiwi grapes strawberry peach&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;USA UK Australia Japan USA UK&lt;/TD&gt;
&lt;TD&gt;USA UK Australia Japan&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;FOOTBALL BasketBall basketball Hockey football&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;Football basketball hockey&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 12 Mar 2019 13:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542382#M149868</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-03-12T13:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542391#M149871</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x $80.;
cards;
apple orange kiwi apple grapes strawberry peach kiwi peach
USA UK Australia Japan USA UK
FOOTBALL BasketBall basketball Hockey football 
;
run;
data want;
 set have;
 array a{999} $ 100;
 n=0;
 do i=1 to countw(x,' ');
  temp=lowcase(scan(x,i,' '));
  if temp not in a then do;	n+1;a{n}=temp;end;
 end;
 want=catx(' ',of a{*});
 drop n i a: temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Mar 2019 14:07:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542391#M149871</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-12T14:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542449#M149887</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string :$200.;
infile datalines dlm=',';
datalines;
apple orange kiwi apple grapes strawberry peach kiwi peach
USA UK Australia Japan USA UK
FOOTBALL BasketBall basketball Hockey football
;

data want(keep=string newstring);
   set have;
   newstring=scan(string, 1, ' ');
   do i=2 to countw(string,' ');
      word=scan(string, i, ' ');
      found=find(newstring, word, 'it');
      if found=0 then newstring=catx(' ', newstring, word);
   end;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives 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-left" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27878i89729D05C9C83E4F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 15:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542449#M149887</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-12T15:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542583#M149927</link>
      <description>&lt;P&gt;With perl regular expression matching:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input str $80.;
cards;
apple orange kiwi apple grapes strawberry peach kiwi peach
USA UK Australia Japan USA UK
FOOTBALL BasketBall basketball Hockey football 
;

data want;
if not prxId then prxId + prxParse("s/\b(\w{2,})\b(.*)\b(\1\s*)\b/\1\2/io");
set have;
wantStr = str;
do i = 1 to 100 until (times=0);
    call prxChange(prxId,1,wantStr,wantStr,len,trunc,times);
    end;
drop i prxId len trunc times;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;         Obs    str

          1     apple orange kiwi apple grapes strawberry peach kiwi peach
          2     USA UK Australia Japan USA UK
          3     FOOTBALL BasketBall basketball Hockey football

         Obs    wantStr

          1     apple orange kiwi grapes strawberry peach
          2     USA UK Australia Japan
          3     FOOTBALL BasketBall Hockey
&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Mar 2019 21:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542583#M149927</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-12T21:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542734#M149979</link>
      <description>&lt;P&gt;I think you should use FINDW(), would be better.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 12:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542734#M149979</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-13T12:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542775#M149995</link>
      <description>&lt;P&gt;Thank you all for your responses, gained some new approach of programming.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 13:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542775#M149995</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-03-13T13:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542898#M150058</link>
      <description>&lt;P&gt;You asked an interesting question and got some interesting answers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can help others further by marking one of the provided answers as the solution (not this one).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 17:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/542898#M150058</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-03-13T17:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/567655#M159655</link>
      <description>&lt;P&gt;I am hoping someone can help with this. I have a similar problem and the code posted her worked but I have over 20 variables with this sort of repeated strings. Do I have to do this over and over for all 20+ variables? Does anyone know any shorter way to do this for multiple variables at once? Can we use this in an array to achieve the same result for many variables?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 15:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/567655#M159655</guid>
      <dc:creator>dee7</dc:creator>
      <dc:date>2019-06-20T15:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/567876#M159753</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278675"&gt;@dee7&lt;/a&gt;&amp;nbsp;&amp;nbsp;Welcome to SAS Communities. I recommend you ask a new question, supplying the data you have and the data you want in the form of SAS data steps using the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;datalines&lt;/FONT&gt;&amp;nbsp;statement to supply the data in each case. More people will see the question and so it should get answered more quickly and with a wider range of solutions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect an answer could involve using one of the dictionary tables and macro variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Feel free to provide a link to this question also, if desired, but all necessary information should ideally be in your question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 11:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/567876#M159753</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-06-21T11:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeated substring in String/Observation from the string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/615656#M180099</link>
      <description>&lt;P&gt;The below code is sometimes excluding the&amp;nbsp; substring with a minor difference in the spelling . Tried with both FIND and FINDW but it is not excluding the exact matching word. In the below example &lt;STRONG&gt;Japan and Japanese&lt;/STRONG&gt; are two different words but when using find function JAPAN is getting excluded because of JAPANESE , similarly in the last row when both &lt;STRONG&gt;FATESTCD and FATEST&lt;/STRONG&gt; are present only FATESTCD is present , FATEST is getting excluded. Only the exact word should get removed ,but its not happening here.Any suggestions/updates on this.&lt;/P&gt;
&lt;P&gt;How can we try this using PRXMATCH,?&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=',';
datalines;
apple orange kiwi apple grapes strawberry peach kiwi peach
China USA UK Australia Japanese USA UK Australian Japan Chinase
FOOTBALL BasketBall basketball Hockey football
FACAT FATESTCD FATEST FAOBJ STDT STDTC VISIT VISITNUM
;

data want(keep=string newstring);
   set have;
   newstring=scan(string, 1, ' ');
   do i=2 to countw(string,' ');
      word=scan(string, i, ' ');
      found=find(newstring, word, 'it');&lt;BR /&gt;      *found=findw(newstring, word, 'it');;
      if found=0 then newstring=catx(' ', newstring, word);
   end;
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>Tue, 07 Jan 2020 13:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeated-substring-in-String-Observation-from-the/m-p/615656#M180099</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2020-01-07T13:24:05Z</dc:date>
    </item>
  </channel>
</rss>

