<?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: count of the number of one in column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464775#M118513</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889"&gt;@soham_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;and the values are other than 0 and 1 also in the real time data&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is an important detail that should have been mentioned in the original post, as we can only go by the example you give us, and we can't write code for other data that is different than the example you give.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, where the values can be other than 0 or 1, you can use PROC FREQ, or do this counting of values that equal 1 in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have end=eof;
    array v var1-var7;
    array c count1-count7;
    do i=1 to 7; 
         if v(i)=1 then c(i)+1;
    end;
    if eof then output;
    keep var1-var7;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 May 2018 14:37:38 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-05-24T14:37:38Z</dc:date>
    <item>
      <title>count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464765#M118508</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a data set like below , i want to count the number of One (1) present in each variable&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data have;&lt;BR /&gt;infile cards dlm= '09'x;&lt;BR /&gt;input Var1-var7;&lt;BR /&gt;cards;&lt;BR /&gt;0 0 0 0 1 1 1&lt;BR /&gt;0 0 0 0 0 1 1&lt;BR /&gt;1 0 0 0 0 0 0&lt;BR /&gt;0 0 1 0 0 0 0&lt;BR /&gt;0 1 0 1 0 1 0&lt;BR /&gt;0 0 0 0 0 0 1&lt;BR /&gt;0 0 1 1 1 0 0&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;0 0 0 1 0 1 0&lt;BR /&gt;0 0 1 1 1 0 0&lt;BR /&gt;1 1 0 0 0 0 0&lt;BR /&gt;0 0 0 0 1 1 1&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;0 0 1 0 0 0 0&lt;BR /&gt;0 1 0 0 0 1 0&lt;BR /&gt;0 0 0 0 0 0 0&lt;BR /&gt;1 0 0 0 0 1 0&lt;BR /&gt;0 0 1 1 0 0 0&lt;/P&gt;&lt;P&gt;;&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;Final output should be like below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Var_name&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Var1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Var2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Var3&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Var4&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Var5&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Var6&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Var7&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 24 May 2018 14:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464765#M118508</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-05-24T14:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464768#M118509</link>
      <description>&lt;P&gt;If the variable values are all ones and zeroes then the easiest might be to sum them:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not say whether you need a data set or a report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc means data=have sum maxdec=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var var1-var7;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 14:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464768#M118509</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-24T14:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464772#M118511</link>
      <description>&lt;P&gt;Hi , i want to create a data set out of it to be used in next step&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the values are other than 0 and 1 also in the real time data&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 14:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464772#M118511</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-05-24T14:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464775#M118513</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889"&gt;@soham_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;and the values are other than 0 and 1 also in the real time data&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is an important detail that should have been mentioned in the original post, as we can only go by the example you give us, and we can't write code for other data that is different than the example you give.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, where the values can be other than 0 or 1, you can use PROC FREQ, or do this counting of values that equal 1 in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have end=eof;
    array v var1-var7;
    array c count1-count7;
    do i=1 to 7; 
         if v(i)=1 then c(i)+1;
    end;
    if eof then output;
    keep var1-var7;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 14:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464775#M118513</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-24T14:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464776#M118514</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
infile cards truncover ;
input Var1-var7;
cards;
0 0 0 0 1 1 1
0 0 0 0 0 1 1
1 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 0 1 0 1 0
0 0 0 0 0 0 1
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 1 0
0 0 1 1 1 0 0
1 1 0 0 0 0 0
0 0 0 0 1 1 1
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 1 0
0 0 0 0 0 0 0
1 0 0 0 0 1 0
0 0 1 1 0 0 0

;
run;

Proc means data=have  maxdec=0;

   var var1-var7;
output out=temp(drop=_:) sum=/autoname;
run;

proc transpose data=temp out=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 May 2018 14:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464776#M118514</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-24T14:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464779#M118516</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889" target="_blank"&gt;@soham_sas&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;wrote:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;and the values are other than 0 and 1 also in the real time data&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Oh well, filter your dataset with a where condition and make the proc means solution work. Yes, it will take one more step but very easy to follow.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 14:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464779#M118516</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-24T14:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464803#M118531</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Borrowing the array definitions from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, you could try the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep = var_name count);
   array v var1-var7;
   array c count1-count7;

   do until(last_obs);
      set have end = last_obs;
      
      do i=1 to 7;
         c[i] + v[i] = 1;
      end;
   end;

   do i=1 to 7;
      var_name = cats('Var',i);
      count    = c[i];
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 15:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464803#M118531</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-05-24T15:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464805#M118533</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22588"&gt;@Amir&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I'm afraid I don't understand this step or see how it helps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;c[i] + v[i] = 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 15:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464805#M118533</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-24T15:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464822#M118541</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps a comment or some brackets would have aided clarity, e.g.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;c[i] + (v[i] = 1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I.e., perform the Boolean test &lt;FONT face="courier new,courier"&gt;v[i] = 1&lt;/FONT&gt; which should return a 1 or a 0, then add that Boolean result to the retained value of &lt;FONT face="courier new,courier"&gt;c[i].&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output appears to match what the OP specified.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that makes more sense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 15:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464822#M118541</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-05-24T15:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464824#M118542</link>
      <description>&lt;P&gt;Okay, this is the equivalent of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; v&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; c&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in my code.&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 15:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464824#M118542</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-24T15:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464830#M118543</link>
      <description>&lt;P&gt;If you do not have millions of values this might be an approach:&lt;/P&gt;
&lt;PRE&gt;Data have;
infile cards truncover ;
input Var1-var7;
cards;
0 0 0 0 1 1 1
0 0 0 0 0 1 1
1 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 2 1 0 1 0
0 0 0 0 0 0 1
0 0 1 1 1 0 0
0 3 0 0 0 0 0
8 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 6 0 0
0 0 0 0 0 0 7
0 0 0 1 0 1 0
0 0 1 1 1 0 0
;
run;
proc transpose data=have out=work.trans;
var var1-var7;
run;

data want;
  set work.trans;
  count1 =count(catx(',',of col:),'1');
  drop col: ;
run;
&lt;/PRE&gt;
&lt;P&gt;if you have more than 100 single digits you may need to estimate the length of the combined delimited string of all the rows of data and build a specific string variable long enough to hold that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set work.trans;
  length str $ 1000;
  str = catx(',',of col:);
  count1 =count(str,'1');
  drop col: str;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 May 2018 16:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/464830#M118543</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-24T16:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: count of the number of one in column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/465080#M118602</link>
      <description>&lt;P&gt;with data set HAVE created, the procedure of frequency summary could be one of the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output onewayfreqs=freq;

proc freq data=have;
   table _all_/nopercent nocum list sparse;
quit;

ods output close;

data final;
   set;
   drop table frequency var1-var7 var_level f_:;
   var_level = strip(coalescec(of f_:));
   if var_level='1';
   var_name = scan(table, -1, '');
   count = frequency;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set have( obs=1);
   array var[7];
   n = dim(var);
   do i=1 to n;
      v_name = vname(var[i]);
      if i=1 then do;
         call execute('proc sql;');
         call execute('   create table final as');
      end; else call execute('   union');
      call execute('   select "'||trim(v_name)||'" as var_name, sum('||trim(v_name)||'=1) as count from have');
      if i=n then do;
         call execute('   ;');
         call execute('quit;');
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 14:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-the-number-of-one-in-column/m-p/465080#M118602</guid>
      <dc:creator>jim_cai</dc:creator>
      <dc:date>2018-05-25T14:29:49Z</dc:date>
    </item>
  </channel>
</rss>

