<?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: Count repeated alphabets in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466490#M119028</link>
    <description>&lt;P&gt;Show us exactly what you want as output.&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 14:56:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-05-31T14:56:05Z</dc:date>
    <item>
      <title>Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466466#M119021</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I have been trying to find repeated alphabets&amp;nbsp;in a given string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example, I have a string like "&lt;STRONG&gt;REPEATED&lt;/STRONG&gt;". I want to find repeated alphabet&amp;nbsp;in it and its count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can someone help me with its code..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 14:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466466#M119021</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-05-31T14:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466469#M119023</link>
      <description>&lt;P&gt;There are numerous examples out there, just search on Goolge.&amp;nbsp; One way would be to output each character as a new observation, then proc freq it. Another would be to loop over each character in the string, and have an array for each letter, and add to that.&amp;nbsp; The real question here is why?&amp;nbsp; I don't see any value in counting characters, unless of course you have more than one data item in a variable, which isn't good practice.&amp;nbsp; Post test data, form of a datastep, and what you want to see out for better answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 14:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466469#M119023</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-31T14:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466485#M119026</link>
      <description>&lt;P&gt;Does case matter? For instance in "Aa" do you want a count of 1 for "A" and 1 for "a" or 2 for "A"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really need to provide some example data and what the output would look like as there are several ways to interpret and provide results.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 14:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466485#M119026</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-31T14:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466490#M119028</link>
      <description>&lt;P&gt;Show us exactly what you want as output.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 14:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466490#M119028</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-31T14:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466492#M119029</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
string='REPEATED';
run;
data _null_;
if _n_=1 then do;
 dcl hash H () ;
   h.definekey  ("char") ;
   h.definedata ('char',"count") ;
   h.definedone();
end;
set have;
do _n_=1 to length(string);
char=substr(string,_n_,1);
if h.find() ne 0 then do;count=1;h.add();end;
else do;count=count+1;h.replace();end;
end;
h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 14:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466492#M119029</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-31T14:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466508#M119032</link>
      <description>&lt;P&gt;Why do you need the count of alphabets?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test (keep=String STR_Count STR_Val);
String="REPEATED";
String_=String;
do until (length(String_)=1);
STR_Count=count(String_,substr(String_,1,1));
STR_Val=substr(String_,1,1);
String_=COMPRESS(String_,substr(String_,1,1));
output;
end;
run;

PROC TRANSPOSE data=test out=want(drop=_name_) prefix=Alphabet_;
by String;
id STR_Val;
var STR_Count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If mixed case then use "i" modifier.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test (keep=String STR_Count STR_Val);
String="RePEATED";
String_=String;
do until (length(String_)=1);
STR_Count=count(String_,substr(String_,1,1),'i');
STR_Val=substr(String_,1,1);
String_=COMPRESS(String_,substr(String_,1,1),'i');
output;
end;
run;

PROC TRANSPOSE data=test out=want(drop=_name_) prefix=Alphabet_;
by String;
id STR_Val;
var STR_Count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 15:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466508#M119032</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-31T15:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466519#M119040</link>
      <description>&lt;P&gt;Most simplest:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
string='REPEATED';
run;
data temp;
set have;
grp+1;
do _n_=1 to length(string);
char=char(string,_n_);
output;
end;
run;

proc freq data=temp;
by grp;
tables char/out=want(keep=char count);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 15:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/466519#M119040</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-31T15:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/477549#M123013</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is so ingenious. Thank you.&lt;/P&gt;&lt;P&gt;Can you please tell me why you have used the compress function in the last step?&lt;/P&gt;&lt;P&gt;I tried running the code without it and it continues to run for indefinite time.&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 15:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/477549#M123013</guid>
      <dc:creator>Jay23</dc:creator>
      <dc:date>2018-07-12T15:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/477555#M123015</link>
      <description>&lt;P&gt;Great. Can you please tell me from where I can learn these Hash objects&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 15:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/477555#M123015</guid>
      <dc:creator>Jay23</dc:creator>
      <dc:date>2018-07-12T15:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count repeated alphabets in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/477606#M123037</link>
      <description>&lt;P&gt;genius&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 16:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-repeated-alphabets-in-a-string/m-p/477606#M123037</guid>
      <dc:creator>Jay23</dc:creator>
      <dc:date>2018-07-12T16:48:37Z</dc:date>
    </item>
  </channel>
</rss>

