<?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 # &amp;gt; 0 in observation across variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528173#M73603</link>
    <description>It's common enough, that I could guess what was happening without seeing your code though &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Thu, 17 Jan 2019 21:26:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-01-17T21:26:05Z</dc:date>
    <item>
      <title>Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528142#M73596</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26354i01360E6672CE3A38/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset (example above) that has monthly counts over a 60 month period of time. I want to obtain a count of the number of times the monthly value is &amp;gt; zero across one observation. I don't care to sum variable by variable but to actually know within an observation how many times the reported value is greater than zero across the 60 month period of time. Suggestions?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 20:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528142#M73596</guid>
      <dc:creator>paulusab</dc:creator>
      <dc:date>2019-01-17T20:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528144#M73597</link>
      <description>&lt;P&gt;Please post your data as text, not as an image.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to do this is to simply loop over the variables, check if it's &amp;gt;0 and increment a counter. Or you could transpose it to a long format and then calculate it much easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect in the long run the long format is likely to be a better approach to your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _dates(*) oct2013--Mar2014;

count=0;

do i=1 to dim(_dates);
if _dates(i)&amp;gt;0 then count+1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255982"&gt;@paulusab&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26354i01360E6672CE3A38/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset (example above) that has monthly counts over a 60 month period of time. I want to obtain a count of the number of times the monthly value is &amp;gt; zero across one observation. I don't care to sum variable by variable but to actually know within an observation how many times the reported value is greater than zero across the 60 month period of time. Suggestions?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 20:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528144#M73597</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-17T20:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528160#M73598</link>
      <description>&lt;P&gt;Thank you, that was very helpful. Now if I want to recall the product of that code in another section of the code how do i refer to it? In PROC print the variable looks like it is named "count" but SAS doesn't recognize that (variable is uninitialized).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528160#M73598</guid>
      <dc:creator>paulusab</dc:creator>
      <dc:date>2019-01-17T21:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528163#M73599</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255982"&gt;@paulusab&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, that was very helpful. Now if I want to recall the product of that code in another section of the code how do i refer to it? In PROC print the variable looks like it is named "count" but SAS doesn't recognize that (variable is uninitialized).&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have no idea what that means.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528163#M73599</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-17T21:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528168#M73600</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
	set Have;
	array _dates(*) Oct2013--Sep2018;
	count=0;
	do i=1 to dim(_dates);
	if _dates(i)&amp;gt;0 then count+1;
	end;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result of this code for observation #1 is 60. All months in the time period have a value greater than 0. I want to now use 60 as a denominator in a segment of code later&amp;nbsp;in this program. But SAS doesn't see the result of the prior program as a permanent variable. It's listed as "count" when I look at the newly created dataset. When I use "count"&amp;nbsp;in the code&amp;nbsp;the log shows "variable count is uninitialized". I'm not sure how to recall the variable to use in the code. Does this make sense?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528168#M73600</guid>
      <dc:creator>paulusab</dc:creator>
      <dc:date>2019-01-17T21:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528169#M73601</link>
      <description>Show us how you're trying to use it and where it's not working. The variable only exists in that data set, so your next steps need to reference your WANT data set now, not the HAVE data set.</description>
      <pubDate>Thu, 17 Jan 2019 21:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528169#M73601</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-17T21:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528171#M73602</link>
      <description>&lt;P&gt;Wow, rookie mistake. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528171#M73602</guid>
      <dc:creator>paulusab</dc:creator>
      <dc:date>2019-01-17T21:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528173#M73603</link>
      <description>It's common enough, that I could guess what was happening without seeing your code though &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528173#M73603</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-17T21:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528174#M73604</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array months(6);
input months(*);
cards;
0	4	3	7	6	8
3	7	5	0	5	0
6	8	6	2	8	0
4	7	0	7	9	4
5	8	6	0	5	7
;

data want;
set have;
array t(*) months1--months6;/**group your months vars with a double dash*/
k=compress(catx(',',of t(*)),'0');
want=countw(k);
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528174#M73604</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-17T21:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528176#M73605</link>
      <description>What happens if a number is 10, 20, 101 etc?</description>
      <pubDate>Thu, 17 Jan 2019 21:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528176#M73605</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-17T21:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528177#M73606</link>
      <description>&lt;P&gt;Doesn't affect, coz i am counting words 10 would become 1 still counting as greater than zero&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array months(6);
input months(*);
cards;
101	4	30	7	6	8
3	7	20	0	5	0
10	8	6	2	8	0
4	7	0	7	9	4
5	8	6	0	5	7
;

data want;
set have;
array t(*) months1--months6;/**group your months vars with a double dash*/
k=compress(catx(',',of t(*)),'0');
want=countw(k);
drop k;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;hence the reason I used catx instead of cats&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 21:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528177#M73606</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-17T21:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528182#M73607</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array months(6);
input months(*);
cards;
101	4	30	7	6	8
3	7	20	0	5	0
10	8	6	2	8	0
4	7	0	7	9	4
5	8	6	0	5	7
;
data want;
set have;
_t=put(0,rb8.);
array t(*) months1-months6;/**group your months vars with a double dash*/
want = n(of t(*))-count(peekclong (addrlong(t[1]), 48),_t) ;
drop _t;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528182#M73607</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-17T22:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528185#M73608</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;What about a custom function via FCMP that can then take an array or list of variables as an argument? I think that's in SASware&amp;nbsp;Ballot or the suggestion of one at least&amp;nbsp;but couldn't find it.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528185#M73608</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-17T22:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Counting # &gt; 0 in observation across variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528186#M73609</link>
      <description>&lt;P&gt;Can't agree more. That's what is the difference between a &lt;STRONG&gt;professional thinking(yours)&lt;/STRONG&gt; and somebody who merely plays video games using SAS. Kudos to your thoughts.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-gt-0-in-observation-across-variables/m-p/528186#M73609</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-17T22:21:27Z</dc:date>
    </item>
  </channel>
</rss>

