<?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 Amount by ID, Month and Type in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201853#M50419</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You mentioned SUM in the subject of your discussion, thus can we presume that you have multiple entries for given ids, dates and types? If so, something like the following should give you an idea of how to solve your problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat date ddmmyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format date ddmmyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile cards dlm=',';&lt;/P&gt;&lt;P&gt;&amp;nbsp; input Account_ID Date Amount Type $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;123,12/06/2013,100,Child&lt;/P&gt;&lt;P&gt;123,14/06/2013,200,Adult&lt;/P&gt;&lt;P&gt;456,01/07/2013,-50,Child&lt;/P&gt;&lt;P&gt;456,01/07/2013,100,Child&lt;/P&gt;&lt;P&gt;456,10/08/2013,250,Adult&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; month=month(date);&lt;/P&gt;&lt;P&gt;&amp;nbsp; combination=catx('_',put(date,monname.),type);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by account_id month type;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=need nway;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by account_id combination notsorted;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var amount;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out=need2 (drop=_:) sum=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=need2 out=want (drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by account_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id combination;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var amount;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 15 Mar 2015 17:03:07 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2015-03-15T17:03:07Z</dc:date>
    <item>
      <title>Sum Amount by ID, Month and Type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201851#M50417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm new to SAS. I'm not quite sure how to do this and would appreciate some guidance. I have data like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 308px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66" height="20" width="105"&gt;Account ID&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="75"&gt;Date&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;Amount&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;Type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl66" height="20" style="border-top: none;"&gt;123&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;"&gt;12/06/2013&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Child&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl66" height="20" style="border-top: none;"&gt;123&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;"&gt;14/06/2013&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Adult&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl66" height="20" style="border-top: none;"&gt;456&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;"&gt;01/07/2013&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;-50&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Child&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl66" height="20" style="border-top: none;"&gt;456&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;"&gt;10/08/2013&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;250&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;Adult&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which I would like to sort like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="372"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66" height="20" width="105"&gt;Account ID&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="75"&gt;June+Child&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;July+Child&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;June+Adult&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;August+Adult&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl66" height="20" style="border-top: none;"&gt;123&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt; &lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl66" height="20" style="border-top: none;"&gt;456&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt; &lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;-50&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt; &lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;"&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 16:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201851#M50417</guid>
      <dc:creator>cirrus74</dc:creator>
      <dc:date>2015-03-15T16:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Amount by ID, Month and Type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201852#M50418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what about july+adult&amp;nbsp; ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 16:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201852#M50418</guid>
      <dc:creator>naveen_srini</dc:creator>
      <dc:date>2015-03-15T16:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Amount by ID, Month and Type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201853#M50419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You mentioned SUM in the subject of your discussion, thus can we presume that you have multiple entries for given ids, dates and types? If so, something like the following should give you an idea of how to solve your problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat date ddmmyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format date ddmmyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile cards dlm=',';&lt;/P&gt;&lt;P&gt;&amp;nbsp; input Account_ID Date Amount Type $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;123,12/06/2013,100,Child&lt;/P&gt;&lt;P&gt;123,14/06/2013,200,Adult&lt;/P&gt;&lt;P&gt;456,01/07/2013,-50,Child&lt;/P&gt;&lt;P&gt;456,01/07/2013,100,Child&lt;/P&gt;&lt;P&gt;456,10/08/2013,250,Adult&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; month=month(date);&lt;/P&gt;&lt;P&gt;&amp;nbsp; combination=catx('_',put(date,monname.),type);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by account_id month type;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=need nway;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by account_id combination notsorted;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var amount;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out=need2 (drop=_:) sum=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=need2 out=want (drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by account_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id combination;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var amount;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 17:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201853#M50419</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-03-15T17:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Amount by ID, Month and Type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201854#M50420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Based on how SAS works this would make it harder to work with your data in the future, so I wouldn't recommend this data structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would be harder to later make tally's for each month, quarter or year, by child/adult for example. &lt;/P&gt;&lt;P&gt;Or to filter out which values/records by amount per month i.e. how many accounts had a negative balance in July and belonged to a child?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And what about if you have more than one year of data?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 22:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201854#M50420</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-03-15T22:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sum Amount by ID, Month and Type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201855#M50421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for your help! Much appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And yes, sorry that I failed to clarify earlier, but there are multiple entries in the data which is why I specified sum in the title. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Mar 2015 13:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-Amount-by-ID-Month-and-Type/m-p/201855#M50421</guid>
      <dc:creator>cirrus74</dc:creator>
      <dc:date>2015-03-16T13:00:04Z</dc:date>
    </item>
  </channel>
</rss>

