<?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: sum multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863902#M341197</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;There was an error when i ran your code&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;61 data long;&lt;BR /&gt;62 set have;&lt;BR /&gt;63 array all {*} a--d;&lt;BR /&gt;64 do i 0 1 to dim(all);&lt;BR /&gt;-&lt;BR /&gt;73&lt;BR /&gt;200&lt;BR /&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;65 x = all{i};&lt;BR /&gt;66 output;&lt;BR /&gt;67 end;&lt;BR /&gt;68 keep x;&lt;BR /&gt;69 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.LONG may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2023 20:47:24 GMT</pubDate>
    <dc:creator>CathyVI</dc:creator>
    <dc:date>2023-03-13T20:47:24Z</dc:date>
    <item>
      <title>sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863845#M341183</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I would like to sum my data set and use a proc tabulate to get sum for 1's and 0's.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;data Have;&lt;BR /&gt;input A B C D;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 1&lt;BR /&gt;0 1 1 1&lt;BR /&gt;1 1 0 0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I used the code below but its only gives me value when total =1 or 0, not the value of all totals.&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if a=1 | b=1 |c=1|d=1 then total=1; else total=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I would like my output to have total of a,b,c,d when its 1, and when its 0.&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;Output&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;TD&gt;%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;66.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;33.4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;All&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 18:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863845#M341183</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-03-13T18:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863853#M341184</link>
      <description>&lt;P&gt;Sum rows, or sum columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if a=1 | b=1 |c=1|d=1 then total=1; else total=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;This isn't a sum at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I shouldn't have to guess or ask. Do you want the total number of 1s and the total number of zeros? You don't say this at all.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 18:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863853#M341184</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-13T18:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863897#M341194</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; I want the&lt;SPAN&gt;&amp;nbsp;total number of 1s and the total number of zeros. This is what I showed in my output table. The table shows total number of 1's and 0's. This is how I want my output to look like. Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 20:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863897#M341194</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-03-13T20:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863900#M341195</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set have;
array all {*} a--d;
do i 0 1 to dim(all);
  x = all{i};
  output;
end;
keep x;
run;

proc freq data=long;
tables x;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Mar 2023 20:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863900#M341195</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-13T20:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863902#M341197</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;There was an error when i ran your code&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;61 data long;&lt;BR /&gt;62 set have;&lt;BR /&gt;63 array all {*} a--d;&lt;BR /&gt;64 do i 0 1 to dim(all);&lt;BR /&gt;-&lt;BR /&gt;73&lt;BR /&gt;200&lt;BR /&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;65 x = all{i};&lt;BR /&gt;66 output;&lt;BR /&gt;67 end;&lt;BR /&gt;68 keep x;&lt;BR /&gt;69 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.LONG may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 20:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863902#M341197</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-03-13T20:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863903#M341198</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input A B C D;
datalines;
1 0 1 1
0 1 1 1
1 1 0 0
;
run;

data long;
set have;

array vars(4) a b c d;

do i=1 to dim(vars);
   value = vars(i);
   var = vname(vars(i));
   output;
end;


keep var value;
run;

proc freq data=long;
table value;
run;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;Transpose your data to a long format&lt;/LI&gt;
&lt;LI&gt;Use PROC FREQ to summarize.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Another method may be to summarize and then collate the summary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This seemed easier but both work.&lt;/P&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/253321"&gt;@CathyVI&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to sum my data set and use a proc tabulate to get sum for 1's and 0's.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;data Have;&lt;BR /&gt;input A B C D;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 1&lt;BR /&gt;0 1 1 1&lt;BR /&gt;1 1 0 0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;I used the code below but its only gives me value when total =1 or 0, not the value of all totals.&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if a=1 | b=1 |c=1|d=1 then total=1; else total=0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;I would like my output to have total of a,b,c,d when its 1, and when its 0.&lt;/P&gt;
&lt;P&gt;For example&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;TD&gt;N&lt;/TD&gt;
&lt;TD&gt;%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;66.6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;33.4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;All&lt;/TD&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 20:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863903#M341198</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-03-13T20:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863906#M341199</link>
      <description>&lt;P&gt;Assuming you meant to read in all three lines of data and not just the two your posted code was reading:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input total @@;
datalines;
1 0 1 1
0 1 1 1
1 1 0 0
;

proc freq ;
  tables total;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1678744506257.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81481i8DE3A89CDD0151F7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1678744506257.png" alt="Tom_0-1678744506257.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 21:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863906#M341199</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-13T21:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863911#M341201</link>
      <description>&lt;P&gt;If you are really stuck with data in that form then you can count them yourself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input v1-v4;
datalines;
1 0 1 1
0 1 1 1
1 1 0 0
;

data want;
  set have end=eof;
  array all _numeric_;
  ones+sum(of all[*]);
  zeros+dim(all)-sum(of all[*]);
  if eof then do;
    total=1; n=ones; p=ones/(ones+zeros); output;
    total=0; n=zeros;  p=zeros/(ones+zeros);output;
  end;
  keep total n p ;
run;

proc print;
 sum n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1678745604082.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81484iB3B360880A659A31/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1678745604082.png" alt="Tom_0-1678745604082.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 22:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863911#M341201</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-13T22:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863942#M341211</link>
      <description>&lt;P&gt;That was a typical tablet-typo. The DO needs an equal sign (as the message says):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i = 1 to dim(all);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 06:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-multiple-variables/m-p/863942#M341211</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-14T06:22:26Z</dc:date>
    </item>
  </channel>
</rss>

