<?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: Running sum in a transactions table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82692#M23743</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mike,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I couldn't write it without a sample dataset.&amp;nbsp; And, are you looking for individual transactions during the twelve month periods or a sum of the transactions within a month, or something else altogether?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is the sum of transactions, I would use proc summary to create a file that has the monthly sums for each id for each month of the ten-year period i.e., include a format that converted dates to monyy7..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, I'd use a datastep that only kept the ID number with (1) a 120 cell array to capture all of the months; (2) a loop that went through each of the possible 12 month periods and, in that loop, build a 12 cell array to capture the 12 months and use the sum function to determine if the value was ge 5000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that criterion is reached, output the ID number, &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;exit the loop and begin the process over with the next id's information..&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Jan 2013 21:22:11 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2013-01-22T21:22:11Z</dc:date>
    <item>
      <title>Running sum in a transactions table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82690#M23741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a list of transactions, each with an associated date and account ID. Does anyone know of a simple way of determining if an account has accumulated a threshold number of dollars in a date range (ex. $X in any twelve-month period over the past ten years)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance, I might need to know if an account gave $5000 in any twelve-month period in the past ten years. It sounds very simple, but I cannot find a way to achieve this without either creating a table for each day of the ten-year period or for creating a variable for each transaction in an account's transactional history (which would also yield a very large number of variables).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jan 2013 20:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82690#M23741</guid>
      <dc:creator>mcopple</dc:creator>
      <dc:date>2013-01-22T20:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Running sum in a transactions table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82691#M23742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the dates are SAS date values this may not be too difficult.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc format;&lt;/P&gt;&lt;P&gt;value tdate&lt;/P&gt;&lt;P&gt;/* this is where the work goes on by specifying date ranges of interest*/&lt;/P&gt;&lt;P&gt;'01APR2000'd&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; '31MAR2001'd&lt;/P&gt;&lt;P&gt;'01APR2001'd&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; '31MAR2002'd&lt;/P&gt;&lt;P&gt;'01APR2002'd&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; '31MAR2003'd&lt;/P&gt;&lt;P&gt;'01APR2003'd&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; '31MAR2004'd&lt;/P&gt;&lt;P&gt;'01APR2004'd&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; '31MAR2005'd&lt;/P&gt;&lt;P&gt;'01APR2005'd&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; '31MAR2006'd&lt;/P&gt;&lt;P&gt;'01APR2006'd&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; '31MAR2007'd&amp;nbsp; /* continue as needed to span your time range*/&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would probably build a variety of permanent formats maybe 12 such as tdateJan tdateFeb tdateMar tdateApr (above)&lt;/P&gt;&lt;P&gt;and then change the format in the proc summary below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=yourdata nway;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class AccountId TransActionDate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format TransactionDate Tdate.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var TransactionValue;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output out=TransactionSum (where=(TransactionSum ge 5000)) sum=TransactionSum;&lt;/P&gt;&lt;P&gt;run&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jan 2013 21:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82691#M23742</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-01-22T21:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Running sum in a transactions table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82692#M23743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mike,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I couldn't write it without a sample dataset.&amp;nbsp; And, are you looking for individual transactions during the twelve month periods or a sum of the transactions within a month, or something else altogether?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is the sum of transactions, I would use proc summary to create a file that has the monthly sums for each id for each month of the ten-year period i.e., include a format that converted dates to monyy7..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, I'd use a datastep that only kept the ID number with (1) a 120 cell array to capture all of the months; (2) a loop that went through each of the possible 12 month periods and, in that loop, build a 12 cell array to capture the 12 months and use the sum function to determine if the value was ge 5000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that criterion is reached, output the ID number, &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;exit the loop and begin the process over with the next id's information..&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jan 2013 21:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82692#M23743</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-01-22T21:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Running sum in a transactions table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82693#M23744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input tx_id tx_date account_id amt;&lt;/P&gt;&lt;P&gt;informat tx_date date9.;&lt;/P&gt;&lt;P&gt;format tx_date date9.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 01jan2012 101 1000&lt;/P&gt;&lt;P&gt;2 02jan2012 101 1000&lt;/P&gt;&lt;P&gt;3 03jan2012 101 1000&lt;/P&gt;&lt;P&gt;4 04jan2012 101 1000&lt;/P&gt;&lt;P&gt;5 05jan2012 101 1000&lt;/P&gt;&lt;P&gt;6 06jan2012 101 1000&lt;/P&gt;&lt;P&gt;7 07jan2012 101 1000&lt;/P&gt;&lt;P&gt;8 08jan2012 101 1000&lt;/P&gt;&lt;P&gt;9 09jan2012 101 1000&lt;/P&gt;&lt;P&gt;10 10jan2012 101 1000&lt;/P&gt;&lt;P&gt;11 01jan2012 102 5000&lt;/P&gt;&lt;P&gt;12 01jan2012 103 100&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct account_id from &lt;/P&gt;&lt;P&gt;(select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.account_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,t1.tx_date&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; work.have t1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left outer join work.have t2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on t1.account_id=t2.account_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and t1.tx_date &amp;lt;= t2.tx_date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and intnx('year',t1.tx_date,1)&amp;gt;=t2.tx_date&lt;/P&gt;&lt;P&gt;group by t1.account_id, t1.tx_date&lt;/P&gt;&lt;P&gt;having sum(t2.amt)&amp;gt;=5000) ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2013 16:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Running-sum-in-a-transactions-table/m-p/82693#M23744</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-01-28T16:29:14Z</dc:date>
    </item>
  </channel>
</rss>

