<?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 number of specific string in a char variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410470#M100286</link>
    <description>&lt;P&gt;Show some example input and the desired output for that input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not at all clear what you are summing.&lt;/P&gt;
&lt;P&gt;When I look at your group 2 example&lt;/P&gt;
&lt;PRE&gt;41:31:53:52:32:33:34:35:36:54:53:52:51:61:48:47:46:45:61:62
value  occurrences
55     0
54     1
53     2
52     2
51     1
61     2
62     1
63     0
64     0&lt;/PRE&gt;
&lt;P&gt;I get a total of 9 occurrences of the values or 6 values found. So how do you get 7?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gets the counts of the substrings in group2 as an example:&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines truncover;
   informat string $100.;
   input string;
   array g {9} $ _temporary_    ("55" "54" "53" "52" "51" "61" "62" "63" "64") ;
   array gcount {9};
   do i= 1 to dim(g);
      gcount[i] =count(string,g[i],'it'); 
   end;
   drop i;
datalines;
41:31:53:52:32:33:34:35:36:54:53:52:51:61:48:47:46:45:61:62
;
run;&lt;/PRE&gt;
&lt;P&gt;Gcount1 will have the count of the 55 in the string variable. Gcount9 will have the count of the 64s.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The sum of the counts could be:&lt;/P&gt;
&lt;P&gt;grp2sum= sum(of gcount(*));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would need a separate temporary array and separate counting array (unless you are VERY careful) to use this approach for both groups.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Nov 2017 21:17:01 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-11-03T21:17:01Z</dc:date>
    <item>
      <title>count number of specific string in a char variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410434#M100275</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got a datasæt with many rows and a&amp;nbsp;char variable with content of&amp;nbsp;a list of numbers separated by :&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;41:31:&lt;/STRONG&gt;&lt;STRONG&gt; 53:52:&lt;/STRONG&gt;&lt;STRONG&gt;32:33:34:35:36:&lt;/STRONG&gt;&lt;STRONG&gt;54:53:52:51:61:&lt;/STRONG&gt;&lt;STRONG&gt;48:47:46:45:&lt;/STRONG&gt;&lt;STRONG&gt;61:62&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to count and sum the number of specific numbers to create a classification as this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Group1 when number is in(&lt;STRONG&gt;48,47,46,45,44,43,42,41,31,32,33,34,35,36) and I need to sum the found number of string&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Group2 when number is in(&lt;STRONG&gt;55,54,53,52,51,61,62,63,64,&lt;/STRONG&gt;&lt;STRONG&gt;) and I need to sum the found number of string&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the result is Group1=11 and Group2=7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas how to do it ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 19:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410434#M100275</guid>
      <dc:creator>ANLYNG</dc:creator>
      <dc:date>2017-11-03T19:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: count number of specific string in a char variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410462#M100285</link>
      <description>&lt;P&gt;something like this then u can extend your idea for another one&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
length z $8.;
a= '41:31:53:52:32:33:34:35:36:54:53:52:51:61:48:47:46:45:61:62';
b ='48,47,46,45,44,43,42,41,31,32,33,34,35,36';
sum = 0;
do until(z='');
      count+1;
      z = scan(a, count,":");
	  if find(b,trim(z)) then sum+z;
	  else sum+0;
  
	  end;
	  drop i count z;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Nov 2017 21:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410462#M100285</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-11-03T21:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: count number of specific string in a char variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410470#M100286</link>
      <description>&lt;P&gt;Show some example input and the desired output for that input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not at all clear what you are summing.&lt;/P&gt;
&lt;P&gt;When I look at your group 2 example&lt;/P&gt;
&lt;PRE&gt;41:31:53:52:32:33:34:35:36:54:53:52:51:61:48:47:46:45:61:62
value  occurrences
55     0
54     1
53     2
52     2
51     1
61     2
62     1
63     0
64     0&lt;/PRE&gt;
&lt;P&gt;I get a total of 9 occurrences of the values or 6 values found. So how do you get 7?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gets the counts of the substrings in group2 as an example:&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines truncover;
   informat string $100.;
   input string;
   array g {9} $ _temporary_    ("55" "54" "53" "52" "51" "61" "62" "63" "64") ;
   array gcount {9};
   do i= 1 to dim(g);
      gcount[i] =count(string,g[i],'it'); 
   end;
   drop i;
datalines;
41:31:53:52:32:33:34:35:36:54:53:52:51:61:48:47:46:45:61:62
;
run;&lt;/PRE&gt;
&lt;P&gt;Gcount1 will have the count of the 55 in the string variable. Gcount9 will have the count of the 64s.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The sum of the counts could be:&lt;/P&gt;
&lt;P&gt;grp2sum= sum(of gcount(*));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would need a separate temporary array and separate counting array (unless you are VERY careful) to use this approach for both groups.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 21:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410470#M100286</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-03T21:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: count number of specific string in a char variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410479#M100288</link>
      <description>&lt;P&gt;This is the solution that works for me on my own data&amp;nbsp;- and in additon very nice and elegant&amp;nbsp;solution. Thank you very much.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 21:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410479#M100288</guid>
      <dc:creator>ANLYNG</dc:creator>
      <dc:date>2017-11-03T21:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: count number of specific string in a char variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410490#M100296</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition also look at PRXCHANGE with COUNT .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA test;&lt;BR /&gt;string="41:31:53:52:32:33:34:35:36:54:53:52:51:61:48:47:46:45:61:62";&lt;BR /&gt;group1="48,47,46,45,44,43,42,41,31,32,33,34,35,36";&lt;BR /&gt;group2="55,54,53,52,51,61,62,63,64";&lt;BR /&gt;Count_Group1=COUNT(prxchange("s/(48|47|46|45|44|43|42|41|31|32|33|34|35|36)/G1/i",-1,string),"G1");&lt;BR /&gt;Count_Group2=COUNT(prxchange("s/(55|54|53|52|51|61|62|63|64)/G2/i",-1,string),"G2");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 22:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-number-of-specific-string-in-a-char-variable/m-p/410490#M100296</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-11-03T22:19:09Z</dc:date>
    </item>
  </channel>
</rss>

