<?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 positive record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267284#M52810</link>
    <description>&lt;P&gt;WIDE, being the *wrong* dataset format, again...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID a b c d e f g ;
datalines;
1 1 0 -1 6 9 5 3 -9 6
1 2 3 6 0 0 0 -2 -2 -9
1 2 3 6 0 0 0 -2 -2 -9
2 5 0 -1 6 -9 -5 3 9 6
2 4 -3 -6 0 0 0 -2 2 -9
2 -2 3 6 0 0 0 -2 -2 9
;

data have0;
set have;
obs = _n_;
run;

proc transpose data=have0 out=have1;
by ID obs;
var a -- g;
run;

data have2;
set have1;
positive = col1 &amp;gt; 0;
run;

proc sql;
create table want as
select
    ID,
    _name_ as var,
    sum(positive) as N_Positive
from have2
group by ID, var;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Apr 2016 17:21:31 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-04-29T17:21:31Z</dc:date>
    <item>
      <title>Counting positive record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267276#M52805</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each ID, I want to count the number of positive value for each variable ( a,b ..c) seperately.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I can do the proc means as below 1 by 1 and sql them back but should it be a better way to get the job done.&lt;/P&gt;
&lt;P&gt;Could you please help?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID a b c d e f g ;
datalines;
1 1 0 -1 6 9 5 3 -9 6
1 2 3 6 0 0 0 -2 -2 -9
1 2 3 6 0 0 0 -2 -2 -9
2 5 0 -1 6 -9 -5 3 9 6
2 4 -3 -6 0 0 0 -2 2 -9
2 -2 3 6 0 0 0 -2 -2 9
;
/*for variable a*/
proc means data=have;
by id;
where a&amp;gt;0;
var a;
output out=want_A(drop=_TYPE_ _FREQ_) 
n=N_A_positive;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 16:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267276#M52805</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-04-29T16:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counting positive record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267281#M52808</link>
      <description>&lt;P&gt;First transpose the data set then use sql to get positive values for each of the classification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want(keep=name val);&lt;BR /&gt;set have;&lt;BR /&gt;array v(*) a b c d e f g;&lt;BR /&gt;do i=1 to dim(v);&lt;BR /&gt;val=v(i);&lt;BR /&gt;name=vname(v(i));&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select name,sum(val&amp;gt;0) as freq_pos from want&lt;BR /&gt;group by name;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 17:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267281#M52808</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-04-29T17:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Counting positive record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267282#M52809</link>
      <description>&lt;P&gt;Or a different approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tab;
   set have;
   array v(*) a b c d e f g;
   do i = 1 to dim(v);
      v[i] = (v[i]&amp;gt;0);
   end;
   drop i;
run;

proc summary data=tab;
   var a b c d e f g;
   output out=want (drop= _:) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Apr 2016 17:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267282#M52809</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-29T17:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Counting positive record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267284#M52810</link>
      <description>&lt;P&gt;WIDE, being the *wrong* dataset format, again...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID a b c d e f g ;
datalines;
1 1 0 -1 6 9 5 3 -9 6
1 2 3 6 0 0 0 -2 -2 -9
1 2 3 6 0 0 0 -2 -2 -9
2 5 0 -1 6 -9 -5 3 9 6
2 4 -3 -6 0 0 0 -2 2 -9
2 -2 3 6 0 0 0 -2 -2 9
;

data have0;
set have;
obs = _n_;
run;

proc transpose data=have0 out=have1;
by ID obs;
var a -- g;
run;

data have2;
set have1;
positive = col1 &amp;gt; 0;
run;

proc sql;
create table want as
select
    ID,
    _name_ as var,
    sum(positive) as N_Positive
from have2
group by ID, var;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Apr 2016 17:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267284#M52810</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-04-29T17:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting positive record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267360#M52838</link>
      <description>&lt;P&gt;A single DATA step can do the trick:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;array positive {7};&lt;/P&gt;
&lt;P&gt;array nums {7} a b c d e f g;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 7;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;positive{_n_} = 0;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do _n_=1 to 7;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if nums{_n_} &amp;gt; 0 then positive{_n_} + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The top loop counts the positives, and the bottom loop outputs the results on each observation for that ID.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 23:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-positive-record/m-p/267360#M52838</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-29T23:27:43Z</dc:date>
    </item>
  </channel>
</rss>

