<?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: First 3months transaction amount in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358708#M84313</link>
    <description>&lt;P&gt;Rawindar,&lt;/P&gt;&lt;P&gt;The MONTH() function just gives you the number of the month in the year. Try using just the INTNX() function instead:&lt;/P&gt;&lt;PRE&gt;proc sql;
  select account_no,sum(transamt) as totaltransaction
  from account
  where trans_date between acc_open_date and 
             intnx('month',acc_open_date,3,'SAME')-1
  group by account_no;
quit;&lt;/PRE&gt;&lt;P&gt;By using the SAME alignment you get the same day of month as the base date; I subtracted one from that as the date thus calculated is actually the first date in the fourth month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Søren&lt;/P&gt;</description>
    <pubDate>Mon, 15 May 2017 11:45:04 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2017-05-15T11:45:04Z</dc:date>
    <item>
      <title>First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358700#M84310</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have below dataset with 4 coloumns.As shown below Account opening date is different to every account.&lt;/P&gt;
&lt;P&gt;after that he may transact in first 3months from account opening date or may not transact.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; account;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; account_no $ acc_open_date :&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; trans_date :&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; transamt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; acc_open_date trans_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 15DEC2016 1000&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 16DEC2016 100&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 19DEC2016 100&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 15JAN2017 1000&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 25JAN2017 1000&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 1FEB2017 1000&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 10FEB2017 1000&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 11FEB2017 1000&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 11MAR2017 1000&lt;/P&gt;
&lt;P&gt;08660123 02NOV2016 21MAR2017 1000&lt;/P&gt;
&lt;P&gt;08660456 02JUN2016 21OCT2016 1000&lt;/P&gt;
&lt;P&gt;08660456 02JUN2016 21NOV2016 1000&lt;/P&gt;
&lt;P&gt;08660456 02JUN2016 21DEC2016 1000&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here i would need sum(&lt;FONT face="Courier New"&gt;transamt&lt;/FONT&gt;) for the first 3months(if account open month is NOv then trans amount for NOV DEC JAN&amp;nbsp;from the account opeinng date group by account no.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in this case i need&lt;/P&gt;
&lt;P&gt;08660123 3200&lt;/P&gt;
&lt;P&gt;08660456&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I tried below query but it's not giving me correct result.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; account_no,sum(transamt) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; totaltransaction&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; account &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; month(trans_date) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;between&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; month(acc_open_date) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; month(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,acc_open_date,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;group&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; account_no;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you in adavance.&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 11:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358700#M84310</guid>
      <dc:creator>rawindar</dc:creator>
      <dc:date>2017-05-15T11:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358708#M84313</link>
      <description>&lt;P&gt;Rawindar,&lt;/P&gt;&lt;P&gt;The MONTH() function just gives you the number of the month in the year. Try using just the INTNX() function instead:&lt;/P&gt;&lt;PRE&gt;proc sql;
  select account_no,sum(transamt) as totaltransaction
  from account
  where trans_date between acc_open_date and 
             intnx('month',acc_open_date,3,'SAME')-1
  group by account_no;
quit;&lt;/PRE&gt;&lt;P&gt;By using the SAME alignment you get the same day of month as the base date; I subtracted one from that as the date thus calculated is actually the first date in the fourth month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Søren&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 11:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358708#M84313</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-05-15T11:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358715#M84318</link>
      <description>&lt;P&gt;&amp;nbsp;Asssuming some accounts may have transacted only for 2 months, for eg any account that may have opened only a couple of months ago:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sql&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;select account_no,sum(transamt) as totaltransaction&lt;/P&gt;&lt;P&gt;from account&lt;/P&gt;&lt;P&gt;where intck('month',acc_open_date,trans_date)+&lt;STRONG&gt;1&lt;/STRONG&gt;&amp;lt;=&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;group by account_no;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 12:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358715#M84318</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-05-15T12:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358721#M84320</link>
      <description>&lt;P&gt;Hi Søren/Navin&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks for immediate response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried both of your queries ,Butunfortunately it did not extract any rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thannk you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Rawindarreddy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 12:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358721#M84320</guid>
      <dc:creator>rawindar</dc:creator>
      <dc:date>2017-05-15T12:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358723#M84321</link>
      <description>&lt;P&gt;I tested using your sample that you gave. It did fetch the sum for the id 08660123&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is what i got:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;account_no totaltransaction&lt;/P&gt;&lt;P&gt;----------------------------&lt;/P&gt;&lt;P&gt;08660123 3200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 12:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358723#M84321</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-05-15T12:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358728#M84323</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1535"&gt;@rawindar&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Søren/Navin&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks for immediate response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried both of your queries ,Butunfortunately it did not extract any rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thannk you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Rawindarreddy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For reference:&lt;/P&gt;
&lt;P&gt;This code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data account;
input account_no $ acc_open_date :date9. trans_date :date9. transamt;
format acc_open_date trans_date date9.;
datalines;
08660123 02NOV2016 15DEC2016 1000
08660123 02NOV2016 16DEC2016 100
08660123 02NOV2016 19DEC2016 100
08660123 02NOV2016 15JAN2017 1000
08660123 02NOV2016 25JAN2017 1000
08660123 02NOV2016 1FEB2017 1000
08660123 02NOV2016 10FEB2017 1000
08660123 02NOV2016 11FEB2017 1000
08660123 02NOV2016 11MAR2017 1000
08660123 02NOV2016 21MAR2017 1000
08660456 02JUN2016 21OCT2016 1000
08660456 02JUN2016 21NOV2016 1000
08660456 02JUN2016 21DEC2016 1000
;
run;

proc sql;
select account_no,sum(transamt) as totaltransaction
from account
where intck('month',acc_open_date,trans_date)+1&amp;lt;=3
group by account_no;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;produced this result (SAS 9.4/AIX/EG 7.1):&lt;/P&gt;
&lt;PRE&gt;account_no  totaltransaction
----------------------------
08660123                3200
&lt;/PRE&gt;
&lt;P&gt;Message to all: please use the "little running man" or {i} icons to post SAS code and log. The main posting window scrambles the formatting and adds surplus lines.&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 12:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358728#M84323</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-15T12:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358913#M84373</link>
      <description>&lt;P&gt;&lt;BR /&gt;Thanks Søren/Naveen/Kurt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes it works with&amp;nbsp;both of your queries.Seems to problem with my EG session.It worked in new session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Rawindarreddy&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 04:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358913#M84373</guid>
      <dc:creator>rawindar</dc:creator>
      <dc:date>2017-05-16T04:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: First 3months transaction amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358951#M84379</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1535"&gt;@rawindar&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;Thanks Søren/Naveen/Kurt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes it works with&amp;nbsp;both of your queries.Seems to problem with my EG session.It worked in new session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Rawindarreddy&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;See Maxim 9.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 09:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-3months-transaction-amount/m-p/358951#M84379</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-16T09:03:51Z</dc:date>
    </item>
  </channel>
</rss>

