<?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: add additional row for totals in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207563#M38603</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for the length issue this will fix it:&lt;/P&gt;&lt;P&gt;data combined;&lt;/P&gt;&lt;P&gt;length sort $10.;&lt;/P&gt;&lt;P&gt;set detail1 totals1;&lt;/P&gt;&lt;P&gt;put _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 30 Apr 2015 19:37:35 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2015-04-30T19:37:35Z</dc:date>
    <item>
      <title>add additional row for totals in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207561#M38601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two questions. Question one is if there is a better way to add a totals row to the data. I originally wanted to do it in a data step but couldn't figure out how to do it. Question two is about the last data step. When I put the totals1 and detail1 datasets together, originally I had detail1 listed first like "set detail1 totals1;" but when I did that it kept dropping the "a" in the sort column for the rows in the totals dataset. I thought it was because in the detail1 dataset that came first the sort column was only 1 character so it made the sort column 1 character which cut off the "a" when it started processing the totals1 dataset. So, I tried using the "length" statement but it didn't make any difference. I finally listed the totals1 dataset first and it worked. How could I have done it so that the "a" wasn't dropped?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input @1 h_id 1. @3 p_code $5. @9 a_u 1. @11 r_u 1. @14 start_date mmddyy10. @24&amp;nbsp; end_date mmddyy10. ;&lt;BR /&gt;format start_date end_date mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;1 J5563 2 4 03/17/2014 03/18/2014 &lt;BR /&gt;2 J3363 4 2 03/18/2014 03/19/2014&lt;BR /&gt;1 J4789 2 6 03/19/2014 03/24/2014&lt;BR /&gt;3 J8434 2 2 03/20/2014 03/24/2014&lt;BR /&gt;3 J4444 5 5 03/21/2014 03/24/2014&lt;BR /&gt;1 J5563 3 1 03/24/2014 03/27/2014&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt; create table detail as&lt;BR /&gt; select *&lt;BR /&gt; from have&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt; create table totals as&lt;BR /&gt; select &lt;BR /&gt;&amp;nbsp; h_id,&lt;BR /&gt;&amp;nbsp; min(start_date) as start_date length=4 format=mmddyy10.,&lt;BR /&gt;&amp;nbsp; max(end_date) as end_date length=4 format=mmddyy10.,&lt;BR /&gt;&amp;nbsp; sum(a_u) as a_u,&lt;BR /&gt;&amp;nbsp; sum(r_u) as r_u&lt;BR /&gt; from detail&lt;BR /&gt; group by h_id&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data totals1;&lt;BR /&gt; set totals;&lt;BR /&gt;/* length sort $2;*/&lt;BR /&gt; p_code='636';&lt;BR /&gt; sort=put(h_id,9.)||'a';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data detail1;&lt;BR /&gt; set detail;&lt;BR /&gt;/* length sort $2;*/&lt;BR /&gt; sort=put(h_id,9.);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data combined;&lt;BR /&gt; set totals1 detail1;&lt;BR /&gt;/* length sort $2;*/&lt;BR /&gt; put _all_;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt; create table combined1 as&lt;BR /&gt; select *&lt;BR /&gt; from combined&lt;BR /&gt; order by sort&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 18:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207561#M38601</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2015-04-30T18:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: add additional row for totals in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207562#M38602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This line sort=put(h_id,9.); creates a variable that is 9 characters long. When the value of h_id is one digit you have 8 leading spaces.&lt;BR /&gt;sort=put(h_id,9.)||'a'; creates a variable 10 characters long, same as above but adds one for the 'a'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this will address the specific issue. You want the overriding LENGTH statement before the set so everything gets brought into the data with that property.&lt;/P&gt;&lt;P&gt;data combined;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length sort $ 10 ;&lt;/P&gt;&lt;P&gt;set detail1 totals1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;put _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you don't want the leading blanks use:&lt;/P&gt;&lt;P&gt;sort = strip(put(h_id,9.));&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;sort=cats(put(h_id,9.),'a'); or ignore the put and just use h_id which will be converted to character using the BEST format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 19:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207562#M38602</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-04-30T19:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: add additional row for totals in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207563#M38603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for the length issue this will fix it:&lt;/P&gt;&lt;P&gt;data combined;&lt;/P&gt;&lt;P&gt;length sort $10.;&lt;/P&gt;&lt;P&gt;set detail1 totals1;&lt;/P&gt;&lt;P&gt;put _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 19:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207563#M38603</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-04-30T19:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: add additional row for totals in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207564#M38604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for the total question I'm not sure I understand what you are looking for, try this and see if this is what you want.&amp;nbsp; Sum without group by:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table combined1 as&lt;/P&gt;&lt;P&gt;select *,sum(a_u) as sum_au,sum(r_u) as sum_ru&lt;/P&gt;&lt;P&gt;from combined&lt;/P&gt;&lt;P&gt;order by sort&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 19:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207564#M38604</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-04-30T19:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: add additional row for totals in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207565#M38605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Consider SAS PROC SUMMARY if you must add total (by GROUP var) row - automatically generated for you, and it can handle SUM, MIN, MAX as you are doing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After summarization, look at sorting by _TYPE_ in descending order, filtering out _TYPE_=0 row.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 19:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207565#M38605</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-04-30T19:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: add additional row for totals in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207566#M38606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;Mark Johnson wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;for the total question I'm not sure I understand what you are looking for, try this and see if this is what you want.&amp;nbsp; Sum without group by:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table combined1 as&lt;/P&gt;
&lt;P&gt;select *,sum(a_u) as sum_au,sum(r_u) as sum_ru&lt;/P&gt;
&lt;P&gt;from combined&lt;/P&gt;
&lt;P&gt;order by sort&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;I think you did misunderstand me. If you run my code, it produces the result that I want. I was wondering if there is a better or more efficient way to get to the same result. Specifically I was wondering if it's possible to do it all in a data step. Thanks for the reply.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 20:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207566#M38606</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2015-04-30T20:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: add additional row for totals in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207567#M38607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;Mark Johnson wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;for the length issue this will fix it:&lt;/P&gt;
&lt;P&gt;data combined;&lt;/P&gt;
&lt;P&gt;length sort $10.;&lt;/P&gt;
&lt;P&gt;set detail1 totals1;&lt;/P&gt;
&lt;P&gt;put _all_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 20:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-additional-row-for-totals-in-data-step/m-p/207567#M38607</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2015-04-30T20:26:25Z</dc:date>
    </item>
  </channel>
</rss>

