<?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 Sum Certain values across rows. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-Certain-values-across-rows/m-p/912881#M359818</link>
    <description>&lt;P&gt;Given a table like such:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs    A    B    C    D    E

 1     1    2    1    1    2
 2     2    2    1    2    2
 3     2    3    3    2    2
 4     1    2    3    1    1
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;how do i create a&amp;nbsp; column , summing the number of times the value of 1 occurs in the row?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs    A    B    C    D    E    Count

 1     1    2    1    1    2      3  
 2     2    2    1    2    2      1  
 3     2    3    3    2    2      0  
 4     1    2    3    1    1      3  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jan 2024 17:20:57 GMT</pubDate>
    <dc:creator>mcook</dc:creator>
    <dc:date>2024-01-24T17:20:57Z</dc:date>
    <item>
      <title>Sum Certain values across rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-Certain-values-across-rows/m-p/912881#M359818</link>
      <description>&lt;P&gt;Given a table like such:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs    A    B    C    D    E

 1     1    2    1    1    2
 2     2    2    1    2    2
 3     2    3    3    2    2
 4     1    2    3    1    1
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;how do i create a&amp;nbsp; column , summing the number of times the value of 1 occurs in the row?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs    A    B    C    D    E    Count

 1     1    2    1    1    2      3  
 2     2    2    1    2    2      1  
 3     2    3    3    2    2      0  
 4     1    2    3    1    1      3  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 17:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-Certain-values-across-rows/m-p/912881#M359818</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2024-01-24T17:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Certain values across rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-Certain-values-across-rows/m-p/912883#M359820</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the table values are only 1 digit numbers (0-9), then a simple count function can give the answer. I would combine all variables into a character string and count number 1 there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  data want; 
  	set have; 
	char= catx(',', a, b, c, d, e);
	count= countc(char, '1'); 
proc print; run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2024 18:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-Certain-values-across-rows/m-p/912883#M359820</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2024-01-24T18:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Certain values across rows.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-Certain-values-across-rows/m-p/912935#M359851</link>
      <description>&lt;P&gt;You can use SAS array and examine the values of each column to match with 1, and count them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input A B C D E;
datalines;
 1    2    1    1    2  
 2    2    1    2    2  
 2    3    3    2    2  
 1    2    3    1    1
;
run;

data want;
   set have;
   array x[*] A B C D E;
   count = 0;
   do i = 1 to dim(x);
      if x[i] = 1 then count + 1;
   end;
drop i;
run;
proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2024 05:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-Certain-values-across-rows/m-p/912935#M359851</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2024-01-25T05:37:37Z</dc:date>
    </item>
  </channel>
</rss>

