<?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: How do I calculate sum for each interval (i.e., month)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812234#M320453</link>
    <description>&lt;P&gt;In the program I submitted, you see the statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if service_date^=. then month{1+intck('month',indexdate,service_date)}=pay;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which would overwrite any earlier payment for a given month with the latter payment for the same month.&amp;nbsp; &amp;nbsp;So instead of &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;assigning&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt; an incoming pay value (i.e. "month{...}=pay") as is done above, what do you think should be done with the incoming value of pay?&amp;nbsp; &amp;nbsp;In particular take a look at the&amp;nbsp; SAS.&lt;A href="https://duckduckgo.com/?q=sas+9.4+sum+function&amp;amp;t=h_&amp;amp;ia=web" target="_self"&gt;Sum function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, we can be much more effective and efficient in helping if the problem is fully specified at the start.&amp;nbsp; Otherwise, &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;mission creep&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt; can often make initial responses totally useless, although that's not the case here.&lt;/P&gt;</description>
    <pubDate>Mon, 09 May 2022 17:57:13 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-05-09T17:57:13Z</dc:date>
    <item>
      <title>How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812084#M320388</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like someone to help me out with the following problem. My current table looks like this,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;enrolid&lt;/TD&gt;&lt;TD&gt;indexdate&lt;/TD&gt;&lt;TD&gt;lastdate&lt;/TD&gt;&lt;TD&gt;service_date&lt;/TD&gt;&lt;TD&gt;pay&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;08/03/2019&lt;/TD&gt;&lt;TD&gt;12/31/2019&lt;/TD&gt;&lt;TD&gt;09/05/2019&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;08/03/2019&lt;/TD&gt;&lt;TD&gt;12/31/2019&lt;/TD&gt;&lt;TD&gt;11/06/2019&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;01/01/2019&lt;/TD&gt;&lt;TD&gt;06/30/2019&lt;/TD&gt;&lt;TD&gt;03/30/2019&lt;/TD&gt;&lt;TD&gt;$5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;01/01/2019&lt;/TD&gt;&lt;TD&gt;06/30/2019&lt;/TD&gt;&lt;TD&gt;06/23/2019&lt;/TD&gt;&lt;TD&gt;$5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;01/01/2019&lt;/TD&gt;&lt;TD&gt;06/30/2019&lt;/TD&gt;&lt;TD&gt;06/25/2019&lt;/TD&gt;&lt;TD&gt;$7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3*&lt;/TD&gt;&lt;TD&gt;01/01/2019&lt;/TD&gt;&lt;TD&gt;12/31/2019&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key:&amp;nbsp;&lt;/P&gt;&lt;P&gt;indexdate = follow-up start date&lt;/P&gt;&lt;P&gt;last_date = follow-up last date&lt;/P&gt;&lt;P&gt;service_date = date of each claim&lt;/P&gt;&lt;P&gt;pay = total cost for each claim&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table I want is this,&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Enrolid&lt;/TD&gt;&lt;TD&gt;month1&lt;/TD&gt;&lt;TD&gt;month2&lt;/TD&gt;&lt;TD&gt;month3&lt;/TD&gt;&lt;TD&gt;month4&lt;/TD&gt;&lt;TD&gt;month5&lt;/TD&gt;&lt;TD&gt;month6&lt;/TD&gt;&lt;TD&gt;month7&lt;/TD&gt;&lt;TD&gt;month8&lt;/TD&gt;&lt;TD&gt;month9&lt;/TD&gt;&lt;TD&gt;month10&lt;/TD&gt;&lt;TD&gt;month11&lt;/TD&gt;&lt;TD&gt;month12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$5&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$12&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I would like to calculate the cost for each month of follow-up.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If there was no claim for each month of follow-up, then it would be $0&lt;/LI&gt;&lt;LI&gt;For the months after the follow-up duration, then the cost would be null&lt;UL&gt;&lt;LI&gt;ex) For patient 1, there are only 5 months of follow-up duration, so from month6 and after the cost would be null or "." ;&lt;/LI&gt;&lt;LI&gt;*Compared to patient 3, even though he didn't have any claims all months during the follow-up duration would be $0.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;I would like to extend the follow-up duration to 48 months.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure what happened but my earlier posts got deleted, so I'm reposting them. Please let me know if you need any clarification.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 08:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812084#M320388</guid>
      <dc:creator>jsyang56</dc:creator>
      <dc:date>2022-05-09T08:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812114#M320404</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input enrolid	(indexdate	lastdate service_date) (: mmddyy12.)		pay : dollar32.;
format indexdate	lastdate service_date mmddyy10. pay dollar32.;
cards;
1	08/03/2019	12/31/2019	09/05/2019	$10
1	08/03/2019	12/31/2019	11/06/2019	$10
2	01/01/2019	06/30/2019	03/30/2019	$5
2	01/01/2019	06/30/2019	06/23/2019	$5
2	01/01/2019	06/30/2019	06/25/2019	$7
3	01/01/2019	12/31/2019	.	.
;

data temp;
 set have;
 month=1;
 if not missing(indexdate) and not missing(service_date) then
  month=ceil(yrdif(indexdate,service_date,'age')*12);
run;
proc summary data=temp nway;
class enrolid month;
var pay;
output out=temp2(drop=_type_ _freq_) sum=;
run; 
data month;
do month=1 to 48;
output;
end;
run;
proc sql;
create table temp3 as
select a.*,coalesce(pay,0) as pay format=dollar32.
 from (select * from (select distinct enrolid from temp2),(select * from month)) as a 
  natural left join temp2;
quit;
proc transpose data=temp3 out=want(drop=_:) prefix=month_;
by enrolid;
var pay;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 May 2022 10:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812114#M320404</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-05-09T10:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812156#M320418</link>
      <description>&lt;P&gt;I think this is a good case for a 48-element array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input enrolid	(indexdate	lastdate service_date) (: mmddyy12.)		pay : dollar32.;
format indexdate	lastdate service_date mmddyy10. pay dollar32.;
cards;
1	08/03/2019	12/31/2019	09/05/2019	$10
1	08/03/2019	12/31/2019	11/06/2019	$10
2	01/01/2019	06/30/2019	03/30/2019	$5
2	01/01/2019	06/30/2019	06/23/2019	$5
2	01/01/2019	06/30/2019	06/25/2019	$7
3	01/01/2019	12/31/2019	.       	.
;
data want (drop=m indexdate lastdate service_date pay);
  do until (last.enrolid);
    set have;
    by enrolid;
    array month{48};
    if service_date^=. then month{1+intck('month',indexdate,service_date)}=pay;
  end;
  
  do m=1 to intck('month',indexdate,lastdate)+1;
    if month{m}=. then month{m}=0;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 May 2022 13:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812156#M320418</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-09T13:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812176#M320427</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your input! With your method I'm like 90% done, the only part I'm missing is that I would like months after their follow-up duration (months between the last_date and indexdate) to be null.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For example, patient 2's costs after month 6 should be null&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;However, the current data set has all months without any values to be $0, instead of null. How would you incorporate the last_date into your code?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 14:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812176#M320427</guid>
      <dc:creator>jsyang56</dc:creator>
      <dc:date>2022-05-09T14:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812177#M320428</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your input! With your solution, I'm 90% close to being done. Currently, each month only shows one pay, instead of the sum of multiple 'pay' rows. How would you modify it to include multiple rows of pay for each month?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, from the table that looks like this,&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Enrolid&lt;/TD&gt;&lt;TD&gt;indexdate&lt;/TD&gt;&lt;TD&gt;lastdate&lt;/TD&gt;&lt;TD&gt;service date&lt;/TD&gt;&lt;TD&gt;pay&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;01/01/2019&lt;/TD&gt;&lt;TD&gt;06/30/2019&lt;/TD&gt;&lt;TD&gt;06/23/2019&lt;/TD&gt;&lt;TD&gt;$5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;01/01/2019&lt;/TD&gt;&lt;TD&gt;06/30/2019&lt;/TD&gt;&lt;TD&gt;06/25/2019&lt;/TD&gt;&lt;TD&gt;$7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;01/01/2019&lt;/TD&gt;&lt;TD&gt;06/30/2019&lt;/TD&gt;&lt;TD&gt;06/25/2019&lt;/TD&gt;&lt;TD&gt;$12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code makes it look like this&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;enrolid&lt;/TD&gt;&lt;TD&gt;month1&lt;/TD&gt;&lt;TD&gt;month2&lt;/TD&gt;&lt;TD&gt;month3&lt;/TD&gt;&lt;TD&gt;month4&lt;/TD&gt;&lt;TD&gt;month5&lt;/TD&gt;&lt;TD&gt;month6&lt;/TD&gt;&lt;TD&gt;month7&lt;/TD&gt;&lt;TD&gt;month8&lt;/TD&gt;&lt;TD&gt;month9&lt;/TD&gt;&lt;TD&gt;month10&lt;/TD&gt;&lt;TD&gt;month11&lt;/TD&gt;&lt;TD&gt;month12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$0&lt;/TD&gt;&lt;TD&gt;$12&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;UL&gt;&lt;LI&gt;Only showing the last pay row for each month, instead of sum of pay&lt;UL&gt;&lt;LI&gt;So, month6 should be $24 instead of $12.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other than that this is exactly what I wanted the table to look like!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 14:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812177#M320428</guid>
      <dc:creator>jsyang56</dc:creator>
      <dc:date>2022-05-09T14:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812234#M320453</link>
      <description>&lt;P&gt;In the program I submitted, you see the statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if service_date^=. then month{1+intck('month',indexdate,service_date)}=pay;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which would overwrite any earlier payment for a given month with the latter payment for the same month.&amp;nbsp; &amp;nbsp;So instead of &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;assigning&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt; an incoming pay value (i.e. "month{...}=pay") as is done above, what do you think should be done with the incoming value of pay?&amp;nbsp; &amp;nbsp;In particular take a look at the&amp;nbsp; SAS.&lt;A href="https://duckduckgo.com/?q=sas+9.4+sum+function&amp;amp;t=h_&amp;amp;ia=web" target="_self"&gt;Sum function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, we can be much more effective and efficient in helping if the problem is fully specified at the start.&amp;nbsp; Otherwise, &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;mission creep&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt; can often make initial responses totally useless, although that's not the case here.&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 17:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812234#M320453</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-09T17:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812241#M320455</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all, I really appreciate the time and effort you put into this problem and helping me out. I believe the original problem includes the sum of pay (e.g., patient 2, month 6), but maybe I should have been more clear with my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried different ways to incorporate the 'sum' function to the code, but nothing seems to be working. Can you provide me with some hints, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have tried,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; if service_date^=. then month{1+intck('month',indexdate,service_date)}= sum(pay);

 if service_date^=. then month{1+intck('month',indexdate,service_date)}= sum(of pay);

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is probably super basic, but I'm very new to this so please bear with me!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 18:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812241#M320455</guid>
      <dc:creator>jsyang56</dc:creator>
      <dc:date>2022-05-09T18:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812272#M320471</link>
      <description>&lt;P&gt;You want to sum the incoming PAY value with any value already present for the corresponding month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e., you want something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;month{m}=sum(month{m},pay);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where m above is a stand in for 1 plus the number of months between indexdate and service_date.&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 22:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812272#M320471</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-09T22:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate sum for each interval (i.e., month)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812288#M320480</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input enrolid	(indexdate	lastdate service_date) (: mmddyy12.)		pay : dollar32.;
format indexdate	lastdate service_date mmddyy10. pay dollar32.;
cards;
1	08/03/2019	12/31/2019	09/05/2019	$10
1	08/03/2019	12/31/2019	11/06/2019	$10
2	01/01/2019	06/30/2019	03/30/2019	$5
2	01/01/2019	06/30/2019	06/23/2019	$5
2	01/01/2019	06/30/2019	06/25/2019	$7
3	01/01/2019	12/31/2019	.	.
;

data temp;
 set have;
 month=1;
 if not missing(indexdate) and not missing(service_date) then
  month=ceil(yrdif(indexdate,service_date,'age')*12);
run;
proc summary data=temp nway;
class enrolid month;
var pay;
output out=temp2(drop=_type_ _freq_) sum=;
run; 

proc summary data=temp2 nway;
class enrolid ;
var month pay;
output out=temp22(drop=_type_ _freq_) max= ;
run; 
data temp23;
 set temp22;
 _pay=0;
 if not missing(pay) then do;
 do month=1 to month;
  output;
 end;
 end;
 else do;
 do month=1 to 48;
  output;
 end;
 end;
drop pay;
run;


data month;
do month=1 to 48;
output;
end;
run;
proc sql;
create table temp3 as
select a.*, coalesce(pay,_pay) as pay format=dollar32.
 from (select * from (select distinct enrolid from temp2),(select * from month)) as a 
  natural left join temp23
  natural left join temp2;
quit;
proc transpose data=temp3 out=want(drop=_:) prefix=month_;
by enrolid;
var pay;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 May 2022 03:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-sum-for-each-interval-i-e-month/m-p/812288#M320480</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-05-10T03:31:25Z</dc:date>
    </item>
  </channel>
</rss>

