<?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 count the number of successive repeating characters in string in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310023#M20908</link>
    <description>&lt;P&gt;Hi! I have a string made up of digits which is 18 characters long. I need to count the number of repeating digits starting from the beginning of the string. That is, given substr(myString,1,1), how many repeating characters are in the rest of the string starting at substr(myString,2,18).&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;'00000' should output 4 'coz there are 4 0s following&amp;nbsp;the one at the beginning of the string&lt;/P&gt;
&lt;P&gt;'100000' should output 0 'coz there are no following 1s after the first one&lt;/P&gt;
&lt;P&gt;'1100000222' should output 1 'coz there is one &lt;SPAN&gt;following 1 after the first one&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;'02200000' should output 0 'coz there are no 0s following the one at the beginning of the string&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;'002200000' should output 1 'coz there is one&amp;nbsp;0 following the one at the beginning of the string&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can anyone help me with this? I'm in sas eg 7 12.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Nov 2016 11:29:27 GMT</pubDate>
    <dc:creator>ak2</dc:creator>
    <dc:date>2016-11-08T11:29:27Z</dc:date>
    <item>
      <title>count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310023#M20908</link>
      <description>&lt;P&gt;Hi! I have a string made up of digits which is 18 characters long. I need to count the number of repeating digits starting from the beginning of the string. That is, given substr(myString,1,1), how many repeating characters are in the rest of the string starting at substr(myString,2,18).&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;'00000' should output 4 'coz there are 4 0s following&amp;nbsp;the one at the beginning of the string&lt;/P&gt;
&lt;P&gt;'100000' should output 0 'coz there are no following 1s after the first one&lt;/P&gt;
&lt;P&gt;'1100000222' should output 1 'coz there is one &lt;SPAN&gt;following 1 after the first one&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;'02200000' should output 0 'coz there are no 0s following the one at the beginning of the string&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;'002200000' should output 1 'coz there is one&amp;nbsp;0 following the one at the beginning of the string&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can anyone help me with this? I'm in sas eg 7 12.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 11:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310023#M20908</guid>
      <dc:creator>ak2</dc:creator>
      <dc:date>2016-11-08T11:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310028#M20910</link>
      <description>&lt;P&gt;Useful functions CHAR() and COUNTC()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This may help you get started:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-most-occuring-consecutive-character-in-Email/m-p/260265/highlight/true#M18153" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-most-occuring-consecutive-character-in-Email/m-p/260265/highlight/true#M18153&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 11:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310028#M20910</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-08T11:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310035#M20912</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $18.;
cards;
00000
100000
1100000222
02200000
002200000
;
run;

data want;
set have;
count = 0;
do while (substr(string,count+2,1) = substr(string,1,1));
  count + 1;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Nov 2016 12:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310035#M20912</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-08T12:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310037#M20914</link>
      <description>&lt;P&gt;It can get tricky if you have 18 identical digits. &amp;nbsp;Here's a way to work with that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;length firstchar $ 1;&lt;/P&gt;
&lt;P&gt;firstchar = myString;&lt;/P&gt;
&lt;P&gt;count=0;&lt;/P&gt;
&lt;P&gt;do i=2 to 18;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if substr(myString, i, 1) = firstchar then count+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else i=20; &amp;nbsp; /* could also try leave instead */&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop firstchar i;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 12:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310037#M20914</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-08T12:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310040#M20916</link>
      <description>&lt;P&gt;Since both the substr() and the char() functions simply return a blank when the index lies outside the size of the string variable, a complete sequence of identical digits poses no problem for my code; run this for a test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $18.;
cards;
00000
100000
1100000222
02200000
002200000
111111111111111111
;
run;

data want;
set have;
count = 0;
do while (char(string,count+2) = char(string,1));
  count + 1;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result of the 18-digit string is 17, as (IMO) intended by the OP.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 12:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310040#M20916</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-08T12:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310055#M20921</link>
      <description>This solution is very intuitive and it gave me correct answer on s super small data set, but implementing this on a larger data set turned out to have a bad performance.</description>
      <pubDate>Tue, 08 Nov 2016 13:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310055#M20921</guid>
      <dc:creator>ak2</dc:creator>
      <dc:date>2016-11-08T13:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310056#M20922</link>
      <description>&lt;P&gt;Thank you so much for your help! This worked fine. No performance issue.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 13:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310056#M20922</guid>
      <dc:creator>ak2</dc:creator>
      <dc:date>2016-11-08T13:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310061#M20924</link>
      <description>&lt;P&gt;Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't test CHAR, but SUBSTR can have problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data test1;&lt;BR /&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test='12345';&lt;BR /&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test2 = substr(test, 6, 1);&lt;BR /&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put _all_;&lt;BR /&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Invalid second argument to function SUBSTR at line 6 column 9.&lt;BR /&gt;test=12345 test2=&amp;nbsp; _ERROR_=1 _N_=1&lt;BR /&gt;test=12345 test2=&amp;nbsp; _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: The data set WORK.TEST1 has 1 observations and 2 variables.&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 13:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310061#M20924</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-08T13:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310072#M20929</link>
      <description>&lt;P&gt;A pure function orientated (i.e.not looping) version:&lt;/P&gt;
&lt;PRE&gt;data have;
input string $18.;
cards;
00000
100000
1100000222
02200000
002200000
111111111111111111
;
run;

data want;
  set have;
  num_before=lengthn(scan(string,1,char(string,1),"k"));
  num_after=lengthn(string)-num_before;
run;&lt;/PRE&gt;
&lt;P&gt;It simply uses the first character as a delimiter and length's scan(1).&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 14:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310072#M20929</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-08T14:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310073#M20930</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt; you're right, char() is more robust than substr() when the index flows over.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 14:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310073#M20930</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-08T14:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310298#M20946</link>
      <description>&lt;PRE&gt;

data have;
input string $18.;
cards;
00000
100000
1100000222
02200000
002200000
;
run;
data want;
 set have;
 pid=prxparse('/^(\d)\1*/');
 call prxsubstr(pid,string,p,l);
 want=l-1;
 drop pid p l;
run;

&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Nov 2016 07:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310298#M20946</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-09T07:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: count the number of successive repeating characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310302#M20947</link>
      <description>&lt;P&gt;This one works fine as well. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 07:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-the-number-of-successive-repeating-characters-in-string/m-p/310302#M20947</guid>
      <dc:creator>ak2</dc:creator>
      <dc:date>2016-11-09T07:20:34Z</dc:date>
    </item>
  </channel>
</rss>

