<?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: Remove Duplicate Characters In A String in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53309#M14727</link>
    <description>Repeated characters:&lt;BR /&gt;
change: "YMYDD"&lt;BR /&gt;
to: ?</description>
    <pubDate>Thu, 09 Oct 2008 16:33:55 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-09T16:33:55Z</dc:date>
    <item>
      <title>Remove Duplicate Characters In A String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53307#M14725</link>
      <description>Hi All:&lt;BR /&gt;
&lt;BR /&gt;
I'm having a huge brain cramp today.&lt;BR /&gt;
&lt;BR /&gt;
I want to remove any repeated characters in a character string.  I've gone through all the character functions in the doc and I can't find anything to do what I want.&lt;BR /&gt;
&lt;BR /&gt;
For example:&lt;BR /&gt;
&lt;BR /&gt;
change:  YYYMMDD&lt;BR /&gt;
      to:   YMD&lt;BR /&gt;
&lt;BR /&gt;
Sounds simple, but I just can't seem to wrap my head around this one.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.</description>
      <pubDate>Thu, 09 Oct 2008 15:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53307#M14725</guid>
      <dc:creator>OS2Rules</dc:creator>
      <dc:date>2008-10-09T15:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Characters In A String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53308#M14726</link>
      <description>This macro should work for you:&lt;BR /&gt;
&lt;BR /&gt;
%macro strnodup(strvar);&lt;BR /&gt;
drop __i;&lt;BR /&gt;
__i=1;&lt;BR /&gt;
do until(__i = length(&amp;amp;strvar));&lt;BR /&gt;
  if substr(&amp;amp;strvar,__i,1) = substr(&amp;amp;strvar,__i+1,1) then &lt;BR /&gt;
     &amp;amp;strvar = substr(&amp;amp;strvar,1,__i)!!substr(&amp;amp;strvar,__i+2);&lt;BR /&gt;
  else __i + 1;&lt;BR /&gt;
end;&lt;BR /&gt;
%mend strnodup;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
retain str "YYYMMDD";&lt;BR /&gt;
str_old = str;&lt;BR /&gt;
%strnodup(str);&lt;BR /&gt;
putlog _all_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 09 Oct 2008 16:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53308#M14726</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-10-09T16:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Characters In A String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53309#M14727</link>
      <description>Repeated characters:&lt;BR /&gt;
change: "YMYDD"&lt;BR /&gt;
to: ?</description>
      <pubDate>Thu, 09 Oct 2008 16:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53309#M14727</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-09T16:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Characters In A String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53310#M14728</link>
      <description>HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   RId = prxparse('s/(.)\1+/$1/io');&lt;BR /&gt;
   text = 'YYYMMDD__YDDDM';&lt;BR /&gt;
   call prxchange(RId, -1, text);&lt;BR /&gt;
   put text;&lt;BR /&gt;
run;</description>
      <pubDate>Sat, 11 Oct 2008 05:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53310#M14728</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-10-11T05:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Characters In A String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53311#M14729</link>
      <description>just another way ..... using substr() in 2 ways (as source and as destination)[pre] data ;&lt;BR /&gt;
    set whatever ;&lt;BR /&gt;
    do p= 2 to length( string) while( p le length( string ) ) ;&lt;BR /&gt;
       if substr( string, p, 1) = substr( string, p-1, 1) &lt;BR /&gt;
          then substr( string, p ) = substr( string, p+1 ) ;&lt;BR /&gt;
    end ;&lt;BR /&gt;
    drop p ;&lt;BR /&gt;
run ;[/pre]&lt;BR /&gt;
PeterC&lt;BR /&gt;
&lt;BR /&gt;
sorry, on testing, I found this failed to handle triples. So here are some test data and a working approach[pre]data whatever ;&lt;BR /&gt;
 input string $ ;&lt;BR /&gt;
cards ;&lt;BR /&gt;
qweeertyui&lt;BR /&gt;
opassassaa&lt;BR /&gt;
dfgggfggh&lt;BR /&gt;
jklsxcvb&lt;BR /&gt;
nm,.1234&lt;BR /&gt;
5678tttt&lt;BR /&gt;
ttfghj56&lt;BR /&gt;
data ;&lt;BR /&gt;
    set whatever ;&lt;BR /&gt;
    do p= 2 to length( string) while( p le length( string ) ) ;&lt;BR /&gt;
       if substr( string, p, 1) = substr( string, p-1, 1) then&lt;BR /&gt;
       do ;&lt;BR /&gt;
            substr( string, p ) = substr( string, p+1 ) ;&lt;BR /&gt;
            p = p-1 ;&lt;BR /&gt;
       end ;&lt;BR /&gt;
    end ;&lt;BR /&gt;
    drop p ;&lt;BR /&gt;
run ;[/pre]

17:04 11Oct08 BST&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Peter.C</description>
      <pubDate>Sat, 11 Oct 2008 15:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/53311#M14729</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2008-10-11T15:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Characters In A String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/633566#M77903</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i managed to use your prxchange and prxparse within my proc sql query and it works like a dream. Just wanted to say thank you for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you mind explaining the arguments for&amp;nbsp;&lt;SPAN&gt;prxparse('s/(.)\1+/$1/io')?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 12:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/633566#M77903</guid>
      <dc:creator>az_rahman</dc:creator>
      <dc:date>2020-03-20T12:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Characters In A String</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/700364#M79846</link>
      <description>&lt;P&gt;&lt;STRONG&gt;DISCLOSURE:&lt;/STRONG&gt; &lt;EM&gt;I realize that this is not a timely reply, but since this post comes up in Google searches for "remove duplicate characters in a SAS string", I have decided to inform readers who stumble upon this post through their search about the following new development:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;I recently published a blog post &lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT color="#008000"&gt;&lt;A title="Remove duplicate characters in SAS strings" href="https://blogs.sas.com/content/sgf/2020/11/04/removing-repeated-characters-in-sas-strings/" target="_self"&gt;&lt;FONT color="#FF0000"&gt;Removing repeated characters in SAS strings&lt;/FONT&gt;&lt;/A&gt; in which &lt;SPAN class="break-words"&gt;I create a new user-defined function UNDUPC that removes duplicate characters from SAS strings effectively expanding functionality of the &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1si0i16bcqti7n1jxxxe1hstunq.htm&amp;amp;locale=en" target="_self"&gt;COMPBL function&lt;/A&gt; to all other characters. &lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;A id="ember1128" class="feed-shared-article__meta flex-grow-1 full-width tap-target app-aware-link ember-view" href="https://blogs.sas.com/content/sgf/2020/11/04/removing-repeated-characters-in-sas-strings/" target="_blank" rel="noopener" data-control-name="article_description"&gt;&lt;/A&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 22:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Duplicate-Characters-In-A-String/m-p/700364#M79846</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2020-11-19T22:10:43Z</dc:date>
    </item>
  </channel>
</rss>

