<?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: counts specific values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37939#M9673</link>
    <description>Hello Yk2k,&lt;BR /&gt;
&lt;BR /&gt;
You can use proc SQL/data step with where/if statement depending on your needs. If you provide an example then I could be more specific.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
    <pubDate>Mon, 22 Nov 2010 14:30:26 GMT</pubDate>
    <dc:creator>SPR</dc:creator>
    <dc:date>2010-11-22T14:30:26Z</dc:date>
    <item>
      <title>counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37937#M9671</link>
      <description>Is there any command can be used in data step which comparable to 'countif' function in excel?</description>
      <pubDate>Mon, 22 Nov 2010 05:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37937#M9671</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-22T05:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37938#M9672</link>
      <description>With consideration to Excel and operating across rows, I would say the answer is no.  &lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 22 Nov 2010 12:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37938#M9672</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-22T12:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37939#M9673</link>
      <description>Hello Yk2k,&lt;BR /&gt;
&lt;BR /&gt;
You can use proc SQL/data step with where/if statement depending on your needs. If you provide an example then I could be more specific.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 22 Nov 2010 14:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37939#M9673</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-11-22T14:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37940#M9674</link>
      <description>Hello SPR,&lt;BR /&gt;
&lt;BR /&gt;
I have tried as follows;&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input (a1-a8) (1.);&lt;BR /&gt;
array x {*} a1-a8;&lt;BR /&gt;
do i=1 to dim{x};&lt;BR /&gt;
if x{i}=1 then num+1;&lt;BR /&gt;
end;&lt;BR /&gt;
drop i;&lt;BR /&gt;
datalines;&lt;BR /&gt;
11111111&lt;BR /&gt;
10101010&lt;BR /&gt;
11100110&lt;BR /&gt;
10101101&lt;BR /&gt;
10110111&lt;BR /&gt;
00010110&lt;BR /&gt;
00010100&lt;BR /&gt;
01011101&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
but it still has a problem that counts cumulatively.&lt;BR /&gt;
can you give me a hand to solve this problem?&lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Youngdeok Kim.</description>
      <pubDate>Sun, 05 Dec 2010 07:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37940#M9674</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-12-05T07:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37941#M9675</link>
      <description>Given the input data example you have now provided, please illustrate in a post-reply exactly what "output" result you wish to see in a SAS file.  &lt;BR /&gt;
&lt;BR /&gt;
As I mentioned in a previous reply, COUNTIF in Excel operates across rows, possibly even within a column/cell range, which is your basic challenge -- not a difficult one if you only want to operate on column values within a given row.&lt;BR /&gt;
&lt;BR /&gt;
So, if you can illustrate with an output results example, then it may be possible for others to help.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 05 Dec 2010 12:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37941#M9675</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-12-05T12:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37942#M9676</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
If you want to count on columns then asimple solution may be:&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input (a1-a8) (1.);&lt;BR /&gt;
array x {*} a1-a8;&lt;BR /&gt;
array count {*} count1-count8;&lt;BR /&gt;
do i=1 to dim(x);&lt;BR /&gt;
if x{i}=1 then count{i}+1;&lt;BR /&gt;
end;&lt;BR /&gt;
drop i;&lt;BR /&gt;
datalines;&lt;BR /&gt;
11111111&lt;BR /&gt;
10101010&lt;BR /&gt;
11100110&lt;BR /&gt;
10101101&lt;BR /&gt;
10110111&lt;BR /&gt;
00010110&lt;BR /&gt;
00010100&lt;BR /&gt;
01011101&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Marius</description>
      <pubDate>Sun, 05 Dec 2010 13:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37942#M9676</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-12-05T13:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37943#M9677</link>
      <description>What I expect is to count specific value across rows.&lt;BR /&gt;
&lt;BR /&gt;
In this data example, I want to count '1' within each row.&lt;BR /&gt;
&lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: yk2k</description>
      <pubDate>Sun, 05 Dec 2010 19:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37943#M9677</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-12-05T19:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37944#M9678</link>
      <description>If ALL you want to do is summarize A1-A8 on every row, then you do not need to use an ARRAY:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
  input (a1-a8) (1.);&lt;BR /&gt;
      &lt;BR /&gt;
  num = sum(of a1-a8);&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
11111111&lt;BR /&gt;
10101010&lt;BR /&gt;
11100110&lt;BR /&gt;
10101101&lt;BR /&gt;
10110111&lt;BR /&gt;
00010110&lt;BR /&gt;
00010100&lt;BR /&gt;
01011101&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
      &lt;BR /&gt;
proc print data=a;&lt;BR /&gt;
sum a1-a8 num;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
In the above program, the SUM function is used to summarize A1-A8 on every observation/row and then in the PROC PRINT step, a summary line is displayed which summarizes (in a grand total) the values for A1-A8 and NUM.&lt;BR /&gt;
 &lt;BR /&gt;
Since your variables follow a regular numbered pattern, you can use the OF syntax in the SUM function. If you had differently named variables, then your SUM function would need to be invoked differently:&lt;BR /&gt;
[pre]&lt;BR /&gt;
newvar = sum(a1, wombat, b4, x, koala, somevar, other);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Sun, 05 Dec 2010 20:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37944#M9678</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-12-05T20:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37945#M9679</link>
      <description>The OP has not given an illustration of what is expected on the output side -- again, an illustration of INPUT and OUTPUT (visual perspective) will help....and consider that it may even help the OP determine what is being conveyed as compared to the true requirements.   At this point, it is still unclear what the "result" should look like -- please share a data output example, not words.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 05 Dec 2010 20:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37945#M9679</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-12-05T20:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37946#M9680</link>
      <description>Cynthia already answered your question of how you can do it, but she didn't address your question of why your attempt counts cumulatively.&lt;BR /&gt;
&lt;BR /&gt;
When you use the construct num+1, SAS automatically retains the value across rows.  If you simply added a statement:&lt;BR /&gt;
num=0;&lt;BR /&gt;
&lt;BR /&gt;
before your do loop, it wouldn't end up counting cumulatively.&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Sun, 05 Dec 2010 20:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37946#M9680</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-12-05T20:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37947#M9681</link>
      <description>Hi.&lt;BR /&gt;
I think you should use SAS's sum statement.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
input (a1-a8) (1.);&lt;BR /&gt;
total_sum+ sum(a1=1,a2=1,a3=1,a4=1,a5=1,a6=1,a7=1,a8=1);&lt;BR /&gt;
datalines;&lt;BR /&gt;
11111111&lt;BR /&gt;
10101010&lt;BR /&gt;
11100110&lt;BR /&gt;
10101101&lt;BR /&gt;
10110111&lt;BR /&gt;
00010110&lt;BR /&gt;
00010100&lt;BR /&gt;
01011101&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs;run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 06 Dec 2010 01:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37947#M9681</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-06T01:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: counts specific values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37948#M9682</link>
      <description>I appreciate all of you who have replied my question. My primary question was to see if any option in data step which is comparable to 'countif' is avaiable in SAS and sbb already gave a straight answer. but, I apologize if my question was too ambiguous.&lt;BR /&gt;
Putting 'num=0' prior to 'do loop' solves my next inquiry when primary interest is to count specific value within each row. &lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Youngdeok.</description>
      <pubDate>Mon, 06 Dec 2010 02:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counts-specific-values/m-p/37948#M9682</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-12-06T02:29:23Z</dc:date>
    </item>
  </channel>
</rss>

