<?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: counting occurrences over variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326197#M72613</link>
    <description>&lt;P&gt;In real life, is the key string only 1 character long? &amp;nbsp;If so, Art's solution works just fine. &amp;nbsp;If not, you may need to rethink your approach. &amp;nbsp;Another possibility:&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;array vars {6} var1-var6;&lt;/P&gt;
&lt;P&gt;totcount&amp;nbsp;= 0;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if vars{_n_}='a' then totcount + 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop totcount;&lt;/P&gt;
&lt;P&gt;if totcount &amp;gt;= 2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other details might matter. &amp;nbsp;Does capitalization play a role? &amp;nbsp;Do partial words count? &amp;nbsp;For example, if you are searching for "cancer" would "cancerous" count? &amp;nbsp;The more details you can supply, the better the answer you will receive.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2017 07:45:42 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-01-20T07:45:42Z</dc:date>
    <item>
      <title>counting occurrences over variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326176#M72602</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose I have the following data:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 288pt;" border="0" width="384" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="6" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var3&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var4&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var5&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;a&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;a&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;b&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what I would like to obtain is a new data set consisting of the above data set where the value "a" occurs at least 2 times over the variables var1 to var 4.&lt;/P&gt;
&lt;P&gt;So here I will end up with 1st row because "a" occurs 3 times within var1 - var4,&lt;/P&gt;
&lt;P&gt;and the second row because it occurs 2 times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 04:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326176#M72602</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-01-20T04:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: counting occurrences over variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326177#M72603</link>
      <description>&lt;P&gt;Here is one way to do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input (var1-var6) ($);
  cards;
a a a b b b
a b a b a b
b b b a a a
;

data want;
  set have;
  if countc(catt(of var1-var4),'a') ge 2 then output;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 04:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326177#M72603</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-01-20T04:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: counting occurrences over variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326197#M72613</link>
      <description>&lt;P&gt;In real life, is the key string only 1 character long? &amp;nbsp;If so, Art's solution works just fine. &amp;nbsp;If not, you may need to rethink your approach. &amp;nbsp;Another possibility:&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;array vars {6} var1-var6;&lt;/P&gt;
&lt;P&gt;totcount&amp;nbsp;= 0;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if vars{_n_}='a' then totcount + 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop totcount;&lt;/P&gt;
&lt;P&gt;if totcount &amp;gt;= 2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other details might matter. &amp;nbsp;Does capitalization play a role? &amp;nbsp;Do partial words count? &amp;nbsp;For example, if you are searching for "cancer" would "cancerous" count? &amp;nbsp;The more details you can supply, the better the answer you will receive.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 07:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326197#M72613</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-20T07:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: counting occurrences over variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326214#M72616</link>
      <description>&lt;P&gt;A slight change to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;'s great example should cover words also:&lt;/P&gt;
&lt;PRE&gt;data have;
  input (var1-var6) ($);
  cards;
a a a b b b
a b a b a b
b b b a a a
;
run;

data want;
  set have;
  sum_of_a=6 - countw(tranwrd(catx(',',of var:),"a",""),",","blank");
run;
&lt;/PRE&gt;
&lt;P&gt;What I do is drop any "a" results, then count what is left and take that off total. &amp;nbsp;If you know the other options then you could go the other way of course.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 09:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-occurrences-over-variables/m-p/326214#M72616</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-20T09:51:17Z</dc:date>
    </item>
  </channel>
</rss>

