<?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: Count/Total Transactions in Last X Days in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/399492#M96767</link>
    <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; thanks again for the tip! It took 13 hours on 40MM obs, but it ran and looks good. I can't thank you and the other posters, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;.</description>
    <pubDate>Thu, 28 Sep 2017 13:55:29 GMT</pubDate>
    <dc:creator>Fenton007</dc:creator>
    <dc:date>2017-09-28T13:55:29Z</dc:date>
    <item>
      <title>Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398573#M96432</link>
      <description>&lt;P&gt;I posted this question awhile back and received a great solution via a Hash Object via user Ksharp&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  input CustID TranAmt:dollar6. TranDate:mmddyy10.;
  format TranDate mmddyy10.;
  datalines;
111 $100 6/1/2014
111 $200 6/2/2014
111 $500 6/4/2014
111 $500 6/10/2014
111 $100 6/11/2014
222 $200 6/3/2014
222 $500 6/4/2014
222 $600 6/4/2014
222 $600 6/11/2014
222 $600 6/19/2014
222 $600 6/28/2014
222 $600 6/29/2014
;
run;

data want;
 if _n_=1 then do;
  if 0 then set new(rename=(TranAmt=_TranAmt));
  declare hash h(dataset:'new(rename=(TranAmt=_TranAmt))',hashexp:20,multidata:'y');
  h.definekey('CustID','TranDate');
  h.definedata('_TranAmt');
  h.definedone();
 end;
set new;
count_8day=0;
sum_8day=0;
do i=TranDate-7 to TranDate;
 rc=h.find(key:CustId,key:i);
 do while(rc=0);
  count_8day+1;
  sum_8day+_TranAmt;
  rc=h.find_next(key:CustId,key:i);
 end;
end;
drop i rc _TranAmt;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This works, for "small" datasets, but now I'm working with datasets in the 40-60 million observation range, and the Hash Object solution is throwing an error that's running out of memory.&amp;nbsp; I've posted the HASH solution below for reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I'm trying to solve is&amp;nbsp;count the number of transactions that occured in the last&amp;nbsp;X days. &amp;nbsp;The best example is saying if on 6/11/16, I want to know how many transactions happened in the prior 8 days, so including 6/11, that would be transactions from 6/11 - 6/4, or 3 total transactions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions on how to adapt this for much larger datasets?&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 15:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398573#M96432</guid>
      <dc:creator>Fenton007</dc:creator>
      <dc:date>2017-09-25T15:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398583#M96436</link>
      <description>&lt;P&gt;Just count?&lt;/P&gt;
&lt;P&gt;Used 18Jun2014 as an arbitrary day since NONE of your example data would have been returned for anything related to todays date unless you were looking for 1000 days or so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=new nway;
   where trandate ge ('18Jun2014'd - 8);
   class custid;
   var tranamt;
   output out=want (drop= _:) n=TranCount;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assumed that you meant transaction by custid.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 15:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398583#M96436</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-25T15:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398590#M96438</link>
      <description>&lt;P&gt;When you use hash objects ALL the data loaded into the hash has to be loaded into memory and it looks like you’ve hit the limit in your environment. There’s no way of guaranteeing you won’t ever run out of memory so if you are using colossal data sets you’re better off using an alternative method as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;suggests.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 15:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398590#M96438</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-25T15:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398600#M96440</link>
      <description>&lt;P&gt;I'm not in front of my machine with SAS loaded on it, so I can't test... but I don't believe this will work since it has a hard-coded date.&amp;nbsp; I'm basically trying to do a "rolling" look back 8 days on each record.&amp;nbsp; I didn't realize I didn't include a required output dataset.&amp;nbsp; It's listed below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THank you for your prompt responses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;CustID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;TranAmt&lt;/TD&gt;&lt;TD&gt;TranDate&lt;/TD&gt;&lt;TD&gt;EXPECTED&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1-Jun-14&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;2-Jun-14&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;TD&gt;4-Jun-14&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;TD&gt;10-Jun-14&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;11-Jun-14&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;3-Jun-14&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;TD&gt;4-Jun-14&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;4-Jun-14&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;11-Jun-14&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;19-Jun-14&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;28-Jun-14&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;29-Jun-14&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 25 Sep 2017 16:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398600#M96440</guid>
      <dc:creator>Fenton007</dc:creator>
      <dc:date>2017-09-25T16:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398616#M96443</link>
      <description>&lt;P&gt;Although your example doesn't clarify the issue, I presume you want rolling counts and sums.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if your data is sorted by custid, you could revise your program to process the data one custid at a time, by use of two "do until last.custid" loops containing a SET statement.&amp;nbsp; The first loop would build the hash object one item at a time, and the second would do pretty much what you're doing now.&amp;nbsp; At the end of the second loop, clear the hash object (rc=h.clear()) to recover memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this would be an expensive proposition -&amp;nbsp;adding items to object h one at a time instead of as a sort of "batch load".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll be much better off with temporary arrays (indexed on dates), one for date-specific total count, and one for date-specific total transamt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lobound=%eval(%sysfunc(inputn(01jan2012,date9.))-7);
%let upbound=%sysfunc(inputn(31dec2016,date9.));

data want (keep=custid trandate tranamt count_8day sum_8day);

  array trcnt{&amp;amp;lobound:&amp;amp;upbound} _temporary_;
  array tramt{&amp;amp;lobound:&amp;amp;upbound} _temporary_;
  call missing(of tramt{*},of trcnt{*});
  do until (last.custid);
    set new;
    by custid;
    trcnt{trandate}+1;
    tramt{trandate}+tranamt;
  end;

  do until (last.custid);
    set new;
    by custid;
    count_8day=0;
    sum_8day=0;
    do i=0 to 7;
      count_8day=sum(count_8day,trcnt{trandate-i});
      sum_8day=sum(sum_8day,tramt{trandate-i});
    end;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&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;OL&gt;
&lt;LI&gt;Arrays can be indexed like this:&amp;nbsp;array x{20:40} meaning the lower bound of array X is 20 and the upper bound is 40.&amp;nbsp; Since dates are whole numbers, if you know the minimum and maximum possible dates for your data you can use those as the bounds, and you could use TRANDATE as the array index.&amp;nbsp; Just be sure to move the lower bound down by an extra 7 so that even the lowest incoming date won't go out of range looking at the previous week's history.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Unfortunately you can't declare an array&amp;nbsp;with date literals as bounds.&amp;nbsp; I.e. you can't use:&amp;nbsp;&amp;nbsp;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp; array&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; mydata{&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Sasfont"&gt;'01jan2012'd&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Sasfont"&gt;:&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Sasfont"&gt;'31dec2016'd&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Sasfont"&gt;};&lt;/FONT&gt;&lt;/P&gt;
So you have to ask the macro processor to get that value.&amp;nbsp; That's why I have&amp;nbsp;&amp;nbsp; &lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp; %let&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; lobound=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(01jan2012,date9.))-7);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp; %let&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; upbound=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(31dec2016,date9.));&lt;/FONT&gt;&lt;/P&gt;
and&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp; array&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; trcnt{&amp;amp;lobound:&amp;amp;upbound} &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;_temporary_&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; &amp;nbsp;array&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; tramt{&amp;amp;lobound:&amp;amp;upbound} &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;_temporary_&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;Because this recycles the same array for each custid, it uses a lot less memory than the hash object you are using.&amp;nbsp; Also it's faster than the hash object, since the array is key-indexed.&amp;nbsp; (the hash object might end up being faster if you were retrieving a lot more variables in definedata method).&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 25 Sep 2017 17:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398616#M96443</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-25T17:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398640#M96456</link>
      <description>Thanks for the thorough explanation. Would using Tran_dt as the array index be a problem if there are multiple transactions on the same date for the same cust_id. Ex... cust 111 has 6 obs, all dated 1/1/2016?&lt;BR /&gt;</description>
      <pubDate>Mon, 25 Sep 2017 18:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398640#M96456</guid>
      <dc:creator>Fenton007</dc:creator>
      <dc:date>2017-09-25T18:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398663#M96457</link>
      <description>&lt;P&gt;You appear to want the total count and total tranamt for each date, so notice that the first "do until" group uses:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; trcnt&lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;trandate&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tramt&lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;trandate&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;tranamt&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; trcnt&lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;trandate&lt;SPAN class="token punctuation"&gt;}=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tramt&lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;trandate&lt;SPAN class="token punctuation"&gt;}=&lt;/SPAN&gt;tranamt&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;resulting in one array element per date with accumluated values for that date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, your hash object would have two items if a given date has two records.&amp;nbsp; But when you retrieve those data items, you accumulate the results.&amp;nbsp; This just accumulates data prior to retrieval.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be a problem if you needed something other than accumulations within a date.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 20:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398663#M96457</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-25T20:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398682#M96461</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
	input CustID TranAmt:dollar6. TranDate:mmddyy10.;
	format TranDate mmddyy10.;
	datalines;
111 $100 6/1/2014
111 $200 6/2/2014
111 $500 6/4/2014
111 $500 6/10/2014
111 $100 6/11/2014
222 $200 6/3/2014
222 $500 6/4/2014
222 $600 6/4/2014
222 $600 6/11/2014
222 $600 6/19/2014
222 $600 6/28/2014
222 $600 6/29/2014
;
run;

/*hwo about only loading one custid at a time, following tweak on Ksharp's code should circumvent or at least alleviate ram stress*/
data want_hash;
	if _n_=1 then
		do;
			declare hash h(multidata:'y', ordered:'y');
			h.definekey('TranDate');
			h.definedata('TranDate','_TranAmt');
			h.definedone();

			call missing (_TranAmt);
		end;

	do until (last.custid);
		set new;
		by CustID TranDate;

		if first.Custid then
			rc=h.clear();
		rc=h.add(key:trandate,data:trandate, data:tranamt);
	end;

	do until (last.custid);
		set new;
		by CustID TranDate;
		sum_8day=0;
		count_8day=0;

		do i=TranDate-7 to TranDate;
			rc=h.find(key:i);

			do while(rc=0);
				sum_8day+_TranAmt;
				count_8day+1;
				rc=h.find_next(key:i);
			end;
		end;

		output;
	end;
	drop i rc _TranAmt;
run;

/*this will slow, but a lot easier to code and read*/
proc sql;
	create table want_sql as
		select *, (select sum(tranamt) from new a where a.custid=b.custid and  b.trandate-a.trandate between 0 and 7) as sum_8days,
(select count(*) from new a where a.custid=b.custid and  b.trandate-a.trandate between 0 and 7) as count_8days
from new b
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Sep 2017 23:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398682#M96461</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-09-25T23:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398792#M96500</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt;&amp;nbsp;is right. Hold one group value each time&amp;nbsp; can save a lot more memory .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  input CustID TranAmt:dollar6. TranDate:mmddyy10.;
  format TranDate mmddyy10.;
  datalines;
111 $100 6/1/2014
111 $200 6/2/2014
111 $500 6/4/2014
111 $500 6/10/2014
111 $100 6/11/2014
222 $200 6/3/2014
222 $500 6/4/2014
222 $600 6/4/2014
222 $600 6/11/2014
222 $600 6/19/2014
222 $600 6/28/2014
222 $600 6/29/2014
;
run;

data want;
 if _n_=1 then do;
  if 0 then set new(rename=(TranAmt=_TranAmt));
  declare hash h(hashexp:20,multidata:'y');
  h.definekey('TranDate');
  h.definedata('_TranAmt');
  h.definedone();
 end;

do until(last.CustID);
set new;
by CustID;
 _TranAmt=TranAmt;h.add();
end;


do until(last.CustID);
set new;
by CustID;

count_8day=0;
sum_8day=0;
do i=TranDate-7 to TranDate;
 rc=h.find(key:i);
 do while(rc=0);
  count_8day+1;
  sum_8day+_TranAmt;
  rc=h.find_next(key:i);
 end;
end;

output;
end;

h.clear();
drop i rc _TranAmt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Sep 2017 13:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/398792#M96500</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-26T13:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/399492#M96767</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; thanks again for the tip! It took 13 hours on 40MM obs, but it ran and looks good. I can't thank you and the other posters, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;.</description>
      <pubDate>Thu, 28 Sep 2017 13:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/399492#M96767</guid>
      <dc:creator>Fenton007</dc:creator>
      <dc:date>2017-09-28T13:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count/Total Transactions in Last X Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/399560#M96787</link>
      <description>&lt;P&gt;13 hours?&amp;nbsp;&amp;nbsp; If you have to do this again, I'd strongly suggest using the array solution, which should be noticably faster.&amp;nbsp; In the program code below processing 100,000,000 skinny observaions, the T2 dataset (using arrays) took about half the time to create as the T1 (using hash).&amp;nbsp; About 84 seconds vs 44 on our server.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hash is more flexible, &lt;EM&gt;&lt;STRONG&gt;but when it comes to looking up single values&lt;/STRONG&gt;&lt;/EM&gt;, it is intrinsically slower than arrays, since the latter has a key pointing directly to the array location of data value, whereas hash needs to process the key value before locating the data value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 17:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Total-Transactions-in-Last-X-Days/m-p/399560#M96787</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-28T17:20:20Z</dc:date>
    </item>
  </channel>
</rss>

