<?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 create a summary table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337676#M76724</link>
    <description>&lt;P&gt;Let's say we have a table like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name &amp;nbsp; &amp;nbsp;Year &amp;nbsp; &amp;nbsp;Amount&lt;/P&gt;&lt;P&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001 &amp;nbsp; 50&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001 &amp;nbsp; 60&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 60&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jason &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jason &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 45&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jason &amp;nbsp; &amp;nbsp;2003 &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jason &amp;nbsp; &amp;nbsp;2003 &amp;nbsp; 60&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How do I get to a table like this, with the most efficient way to code. Also suppose there are many years, and I prefer not to hand spell all the year values.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Name &amp;nbsp; &amp;nbsp;2001_total &amp;nbsp; 2002_total &amp;nbsp; &amp;nbsp;2003_total &amp;nbsp; Total&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;110 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 210&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jason &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 85 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;185&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Total &amp;nbsp; &amp;nbsp; &amp;nbsp; 110 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 185 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;395&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Particularly, when you add up two variables, one of which take a missing value, the resulting value is also missing, instead of just equal to the non-missing value and treating the missing value as 0. How to get around that?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2017 00:12:51 GMT</pubDate>
    <dc:creator>apolitical</dc:creator>
    <dc:date>2017-03-03T00:12:51Z</dc:date>
    <item>
      <title>create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337676#M76724</link>
      <description>&lt;P&gt;Let's say we have a table like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name &amp;nbsp; &amp;nbsp;Year &amp;nbsp; &amp;nbsp;Amount&lt;/P&gt;&lt;P&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001 &amp;nbsp; 50&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001 &amp;nbsp; 60&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 60&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jason &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jason &amp;nbsp; &amp;nbsp;2002 &amp;nbsp; 45&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jason &amp;nbsp; &amp;nbsp;2003 &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jason &amp;nbsp; &amp;nbsp;2003 &amp;nbsp; 60&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How do I get to a table like this, with the most efficient way to code. Also suppose there are many years, and I prefer not to hand spell all the year values.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Name &amp;nbsp; &amp;nbsp;2001_total &amp;nbsp; 2002_total &amp;nbsp; &amp;nbsp;2003_total &amp;nbsp; Total&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jim &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;110 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 210&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jason &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 85 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;185&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Total &amp;nbsp; &amp;nbsp; &amp;nbsp; 110 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 185 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;395&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Particularly, when you add up two variables, one of which take a missing value, the resulting value is also missing, instead of just equal to the non-missing value and treating the missing value as 0. How to get around that?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 00:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337676#M76724</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-03-03T00:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337684#M76729</link>
      <description>&lt;P&gt;The easyest way to gat a suumary table is by PROC TABULATE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=have missing ;
calss name year;
var amount;
table name, (year all)*amount*f=comma12.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Mar 2017 01:27:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337684#M76729</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-03T01:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337685#M76730</link>
      <description>&lt;P&gt;The sum function ignores missing values. However, you could create what you want with either proc report, or code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=have;
  var amount;
  by name year notsorted;
  output out=want (drop=_:) sum=total;
run;

proc transpose data=want prefix=total_ out=want (drop=_:);
  var total;
  by name notsorted;
  id year;
run;

data want;
  set want;
  total=sum(of total:);
run;

proc print data=want;
  sum total:;
run;

&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 01:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337685#M76730</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-03T01:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337848#M76797</link>
      <description>This seems to do everything but not give the bottom row of my desired table (total), does it?</description>
      <pubDate>Fri, 03 Mar 2017 14:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337848#M76797</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-03-03T14:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337853#M76801</link>
      <description>&lt;P&gt;It gives the bottom row, just doesn't label it 'Total'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 15:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337853#M76801</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-03T15:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337868#M76805</link>
      <description>&lt;P&gt;Sorry, I missed the bottomn total row. Check next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=have missing ;
calss name year;
var amount;
table (name all='Total'), 
        (year all='Total')*amount*f=comma12.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Mar 2017 15:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337868#M76805</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-03T15:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337889#M76811</link>
      <description>yes the proc print at the end shows the table i want, but how do i save it as a dataset in the work library? thanks.</description>
      <pubDate>Fri, 03 Mar 2017 16:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337889#M76811</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-03-03T16:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: create a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337916#M76821</link>
      <description>&lt;P&gt;Not sure why you would want that, but you could use a datastep. It would required customizing the last step to account for all years actually represented in your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input Name $   Year    Amount;
  cards;
Jim        2001   50
Jim        2001   60
Jim        2002   40
Jim        2002   60
Jason    2002   40
Jason    2002   45
Jason    2003   40
Jason    2003   60
;

proc summary data=have;
  var amount;
  by name year notsorted;
  output out=want (drop=_:) sum=total;
run;

proc transpose data=want prefix=total_ out=want (drop=_:);
  var total;
  by name notsorted;
  id year;
run;

data want (drop=_:);
  set want end=eof;
  total=sum(of total:);
  _total_2001+total_2001;
  _total_2002+total_2002;
  _total_2003+total_2003;
  _total+total;
  output;
  if eof then do;
    total_2001=_total_2001;
    total_2002=_total_2002;
    total_2003=_total_2003;
    total=_total;
    Name='Total';
    output;
  end;
run;

proc print data=want;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 17:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-summary-table/m-p/337916#M76821</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-03T17:25:55Z</dc:date>
    </item>
  </channel>
</rss>

