<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332287#M74775</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wondering if there is any function in SAS which is equivalent to the COUNT function in SPSS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;K&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2017 18:43:33 GMT</pubDate>
    <dc:creator>khalidamin</dc:creator>
    <dc:date>2017-02-13T18:43:33Z</dc:date>
    <item>
      <title>COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332287#M74775</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wondering if there is any function in SAS which is equivalent to the COUNT function in SPSS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;K&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 18:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332287#M74775</guid>
      <dc:creator>khalidamin</dc:creator>
      <dc:date>2017-02-13T18:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332291#M74777</link>
      <description>&lt;P&gt;Not specifically, AFAIK. It's actually a bit annoying, because this is a common question!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, you can easily use an array or other methods to get counts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you post sample data and what you expect as output and we can illustrate ways this can be accomplished.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 18:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332291#M74777</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-13T18:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332329#M74786</link>
      <description>&lt;P&gt;If the set of values you wish to count are all single characters, then you can use the COUNTC and CATS functions as here.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data grades;&lt;BR /&gt;&amp;nbsp; input id 1. (grade_eng grade_hist grade_bio grade_math grade_civics) ($1.);&lt;BR /&gt;&amp;nbsp; npass=countc(cats(of grade_eng--grade_civics),'ABCD');&lt;BR /&gt;&amp;nbsp; put (_all_) (=);&lt;BR /&gt;datalines;&lt;BR /&gt;1ABCDE&lt;BR /&gt;2ABCEE&lt;BR /&gt;3ABEEE&lt;BR /&gt;4AEEEE&lt;BR /&gt;5EEEEE&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it would also work if you were counting a set of single digit numeric values in numeric vars:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; n_ones_and_twos =countc(cats(num1,num2,num3,num4,'12');&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 20:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332329#M74786</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-13T20:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332344#M74789</link>
      <description>&lt;P&gt;For those of use who are not familiar with SPSS, what are you trying to accomplish?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 21:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332344#M74789</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-02-13T21:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332367#M74804</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;I was trying to compute 'count_v' using v1-v3.&lt;BR /&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7209i439E98797DE3F440/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="a.jpg" title="a.jpg" /&gt;&lt;/P&gt;
&lt;P&gt;I followed LinLin's solution using array (&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Horizontal-count-of-number-of-variables-that-meet-criteria-in/td-p/101590" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Horizontal-count-of-number-of-variables-that-meet-criteria-in/td-p/101590&lt;/A&gt;).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;K&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 21:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332367#M74804</guid>
      <dc:creator>khalidamin</dc:creator>
      <dc:date>2017-02-13T21:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332397#M74814</link>
      <description>&lt;P&gt;If the arguments are numeric then you want the N function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;v_count= n(v1,v2,v3);&lt;/P&gt;
&lt;P&gt;or if you can use a list&lt;/P&gt;
&lt;P&gt;v_count = n(of v1-v3);&lt;/P&gt;
&lt;P&gt;or array defined as:&lt;/P&gt;
&lt;P&gt;Array v v1-v3;&lt;/P&gt;
&lt;P&gt;v_count= n(of v(*));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 22:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332397#M74814</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-13T22:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332400#M74815</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;: an SPSS example:&amp;nbsp;&lt;SPAN class="syntax"&gt;COUNT NREAD=MONDE,NZZ,TEMPS,FAZ,BZ,TAZ,MATIN(1,2,3).&lt;/SPAN&gt;&lt;SPAN&gt; Counts all occurences of values 1,2,3 across all the&amp;nbsp;specified variables&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60337"&gt;@khalidamin&lt;/a&gt;:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;'s solution works for both character and numeric, as well as arrays. Take a look at the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data grades;
  input id 1. (v1-v5) ($1.);
  npass=countc(cats(of v:),'1');
  datalines;
111110
211100
311000
410000
500000
run;

data grades2;
  input id v1-v5;
  npass=countc(cats(of v:),'1');
  datalines;
1 1 1 1 1 0
2 1 1 1 0 0
3 1 1 0 0 0
4 1 0 0 0 0
5 0 0 0 0 0
run;

data grades3;
  input id 1. (testa testb testc testd teste) ($1.);
  array v(*) $ testa--teste;
  npass=countc(cats(of v(*)),'1');
  datalines;
111110
211100
311000
410000
500000
run;

data grades4;
  input id testa testb testc testd teste;
  array v(*) testa--teste;
  npass=countc(cats(of v(*)),'1');
  datalines;
1 1 1 1 1 0
2 1 1 1 0 0
3 1 1 0 0 0
4 1 0 0 0 0
5 0 0 0 0 0
run;
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;HTH,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Art, CEO, AnalystFinder.com&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 23:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332400#M74815</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-13T23:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332439#M74826</link>
      <description>&lt;P&gt;And if you are trying to count multi-character values (or multidigit numerics), it can be emulated like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data authors;
  input (author1-author5) ($4. +1);
datalines;
mark art  ruth sam  pete
joe  rick jane john jean
pete art  rick elen jack
run;

data want;
  set authors;
  txt=catx('!',of author:,'!');
  do value='mark','art','jane';
    txt=tranwrd(txt,trim(value)||'!','1!');
  end;
  nauthor=countc(txt,'1');
  put (author:) (=)  / nauthor=;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It can probably be made into a relatively useful macro spss_count such as this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;
%macro spss_count(vars=,values=,countvar=)
  /des="replicate spss count function";
  %local 
     VARS     /*a variable list to be examined for desired values*/
     VALUES   /*a space-separated list of values to count*/
     COUNTVAR /*Name of variable to receive the count */
		;
  _txt=catx('!',&amp;amp;vars,'!');
  %do v=1 %to %sysfunc(countw(&amp;amp;values));
    %let value=%scan(&amp;amp;values,&amp;amp;v)!;
    _txt=tranwrd(_txt,trim("&amp;amp;value"),'1!');
  %end;
  &amp;amp;countvar=countc(_txt,'1');
  drop _txt;
%mend spss_count;


data want2;
  set have;
  %spss_count(vars=of author:,values=mark art jane,countvar=nauthors);
  put (author:) (=) / nauthors=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I leave it to those more facile with proc fcmp to make an efficient user-defined function.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 00:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332439#M74826</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-14T00:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332474#M74842</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60337"&gt;@khalidamin&lt;/a&gt;&amp;nbsp;Your post is still ambiguous. That could be the sum of the columns, or the count of 1s. The assumption that their all 0/1 isn't explicit.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 04:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNT/m-p/332474#M74842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-14T04:16:26Z</dc:date>
    </item>
  </channel>
</rss>

