<?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: How to sum vertically with missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384506#M91828</link>
    <description>&lt;P&gt;Use PROC MEANS 3 times with the SUM option and an output out= statement. Then merge the three datasets together and use the SUM function to get a grand total.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2017 05:11:17 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-08-01T05:11:17Z</dc:date>
    <item>
      <title>How to sum vertically with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384501#M91826</link>
      <description>&lt;P&gt;SAS gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I need to sum a column vertically which could have missing values. sometimes one dataset (dataset 3) is empty as there are no observations. once I have that done I need to sum those weights (verical sums) horizontally.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I am not sure which procedures to use to accomplish this task. please advise.&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg: &lt;U&gt;dataset 1&lt;/U&gt;&lt;/P&gt;&lt;P&gt;variable weight&lt;/P&gt;&lt;P&gt;jack 12&lt;/P&gt;&lt;P&gt;samuel .&lt;/P&gt;&lt;P&gt;tylor 14&lt;/P&gt;&lt;P&gt;monroe 20&lt;/P&gt;&lt;P&gt;kelly .&lt;/P&gt;&lt;P&gt;total weight=46&lt;/P&gt;&lt;P&gt;&lt;U&gt;dataset 2&lt;/U&gt;&lt;/P&gt;&lt;P&gt;variable weight1&lt;/P&gt;&lt;P&gt;kim 58&lt;/P&gt;&lt;P&gt;karla .&lt;/P&gt;&lt;P&gt;cara 25&lt;/P&gt;&lt;P&gt;maya 50&lt;/P&gt;&lt;P&gt;total weight1 =133&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;dataset3&lt;/U&gt;&lt;/P&gt;&lt;P&gt;variable &amp;nbsp;weight2&lt;/P&gt;&lt;P&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;total weight2=0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;the out put needs to have&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;total weight&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;total weight1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;total weight2.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;grand total= total weight+total weight1+ total weight2= 46+133+0=179&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 05:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384501#M91826</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-08-01T05:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum vertically with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384506#M91828</link>
      <description>&lt;P&gt;Use PROC MEANS 3 times with the SUM option and an output out= statement. Then merge the three datasets together and use the SUM function to get a grand total.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 05:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384506#M91828</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-08-01T05:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum vertically with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384508#M91830</link>
      <description>&lt;P&gt;Append all three datasets and then summarize, once with proc means. Use a CLASS statement to get subtotal&amp;nbsp;and totals in one dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 05:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384508#M91830</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-01T05:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum vertically with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384511#M91831</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139130"&gt;@buddha_d&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Please provide your source data always via a working SAS data step so we don't have to do this for you.&lt;/P&gt;
&lt;P&gt;As for your question: You could first combine all your source data sets into one and and an additional variable which holds the name of the source data set. You then can use this additional variable as a classification/grouping variable in any of the SAS Procs which can return the result you're after.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using Proc Tabulate in below sample code but you could also use other Procs like Proc Means, Proc Report or Proc SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
  input name $ weight;
  datalines;
jack 12
samuel .
tylor 14
monroe 20
kelly .
;
run;

data ds2;
  input name $ weight;
  datalines;
kim 58
karla .

;
run;

data ds3;
  input name $ weight;
  datalines;
cara 25
maya 50
;
run;

data ds_all;
  length _inds $41;
  set ds1 ds2 ds3 indsname=_inds;
  inds=_inds;
run;

proc tabulate data=ds_all;
  class inds;
  var weight;
  table inds=' ' all='Total' , weight*sum=' ';
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Aug 2017 05:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384511#M91831</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-08-01T05:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum vertically with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384515#M91832</link>
      <description>&lt;P&gt;Do you know how to get a grand total for just one data set? &amp;nbsp;As you might expect, SAS provides a variety of tools for that. &amp;nbsp;You should learn at least one method if you expect to program with SAS, instead of relying on the board to program basic functionality for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SInce you have three data sets, here's a straightforward approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do until (done1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set dataset1 end=done1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;total_weight + weight;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (done2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set dataset2 end=done2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;total_weight1 + weight1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (done3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set dataset3 end=done3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;total_weight2 + weight2;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;grand_total = total_weight + total_weight1 + total_weight2;&lt;/P&gt;
&lt;P&gt;keep total_: &amp;nbsp;grand_total;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 06:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384515#M91832</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-01T06:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum vertically with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384560#M91847</link>
      <description>&lt;P&gt;Thank you all for your help. It works. Unfortunately, I have big datasets, so that is the reason I couldn't send original file. But the same logic works. Thanks all for helping me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 11:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384560#M91847</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-08-01T11:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum vertically with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384831#M91968</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139130"&gt;@buddha_d&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you all for your help. It works. Unfortunately, I have big datasets, so that is the reason I couldn't send original file. But the same logic works. Thanks all for helping me.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We don't want "big datasets" we want enough to exercise the logic. What is extremely helpful is providing data in the form of a data step.&lt;/P&gt;
&lt;P&gt;With a data step we know the variable types and lengths. We have spend lots of time working on requests and &lt;STRONG&gt;after&lt;/STRONG&gt; 10 or 15 responses the original poster finally admits that a value that looked numeric was actually character, or that looked character was the result of a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 22:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-vertically-with-missing-values/m-p/384831#M91968</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-01T22:41:09Z</dc:date>
    </item>
  </channel>
</rss>

