<?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: assign last month value to previous 2 records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376308#M90313</link>
    <description>&lt;P&gt;Note that you can probably do this directly with INTNX using some of the shift options. But, here's one way using nested INTNX, there's probably a simpler way, but this doesn't depend on the order of the data and can be used anywhere in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, your last entry in your WANT data set is incorrect, it should be 2018, not 2017.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
want = intnx('month', 
                     intnx('qtr', 
                                 intnx('month', run_month, 1, 'b'), 
                                 0, 'e'), 
                                         -1, 'b');
format want date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 16 Jul 2017 06:56:27 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-07-16T06:56:27Z</dc:date>
    <item>
      <title>assign last month value to previous 2 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376302#M90307</link>
      <description>&lt;P&gt;HI All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am currently working on below logic, i tried couple of tricks but didn't got desired results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to group 3 countinues months and assign last month values for previous 2 months including current month record .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;for instance:&lt;/STRONG&gt; dec16,jan17 and feb17 i want to assign as feb17. Basically wants to tried as quarter(not using qtr function).&lt;/P&gt;
&lt;P&gt;i have enclosed the sample code and desired output, your help is appreciable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input run_month:date9.;&lt;BR /&gt;format run_month date9. ;&lt;BR /&gt;datalines;&lt;BR /&gt;01dec2016&lt;BR /&gt;01jan2017&lt;BR /&gt;01feb2017&lt;BR /&gt;01mar2017&lt;BR /&gt;01apr2017&lt;BR /&gt;01may2017&lt;BR /&gt;01jun2017&lt;BR /&gt;01jul2017&lt;BR /&gt;01aug2017&lt;BR /&gt;01sep2017&lt;BR /&gt;01oct2017&lt;BR /&gt;01nov2017&lt;BR /&gt;01dec2017&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="203"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="101"&gt;Months&lt;/TD&gt;
&lt;TD width="102"&gt;Qtr_month&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Dec-16&lt;/TD&gt;
&lt;TD&gt;1-Feb-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Jan-17&lt;/TD&gt;
&lt;TD&gt;1-Feb-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Feb-17&lt;/TD&gt;
&lt;TD&gt;1-Feb-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Mar-17&lt;/TD&gt;
&lt;TD&gt;1-May-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Apr-17&lt;/TD&gt;
&lt;TD&gt;1-May-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-May-17&lt;/TD&gt;
&lt;TD&gt;1-May-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Jun-17&lt;/TD&gt;
&lt;TD&gt;1-Aug-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Jul-17&lt;/TD&gt;
&lt;TD&gt;1-Aug-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Aug-17&lt;/TD&gt;
&lt;TD&gt;1-Aug-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Sep-17&lt;/TD&gt;
&lt;TD&gt;1-Nov-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Oct-17&lt;/TD&gt;
&lt;TD&gt;1-Nov-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Nov-17&lt;/TD&gt;
&lt;TD&gt;1-Nov-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1-Dec-17&lt;/TD&gt;
&lt;TD&gt;1-Feb-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sun, 16 Jul 2017 04:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376302#M90307</guid>
      <dc:creator>sss</dc:creator>
      <dc:date>2017-07-16T04:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: assign last month value to previous 2 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376303#M90308</link>
      <description>&lt;P&gt;Assuming data is sorted and months are continues, try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
        retain count 0; drop count;
        count+1;
        if count=3 then count=0;
        qtr_month = intnx('month',months,count);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Jul 2017 04:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376303#M90308</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-16T04:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: assign last month value to previous 2 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376304#M90309</link>
      <description>&lt;P&gt;I think Shmuel is using the right tools, but the wrong logic. &amp;nbsp;I would try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;retain count 3;&lt;/P&gt;
&lt;P&gt;count = count - 1;&lt;/P&gt;
&lt;P&gt;qtr_month = intnx('month', run_month, count);&lt;/P&gt;
&lt;P&gt;if count=0 then count=3;&lt;/P&gt;
&lt;P&gt;drop count;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jul 2017 05:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376304#M90309</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-16T05:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: assign last month value to previous 2 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376306#M90311</link>
      <description>&lt;P&gt;Yes its works, thank you shmuel and Astounding &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jul 2017 06:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376306#M90311</guid>
      <dc:creator>sss</dc:creator>
      <dc:date>2017-07-16T06:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: assign last month value to previous 2 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376308#M90313</link>
      <description>&lt;P&gt;Note that you can probably do this directly with INTNX using some of the shift options. But, here's one way using nested INTNX, there's probably a simpler way, but this doesn't depend on the order of the data and can be used anywhere in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, your last entry in your WANT data set is incorrect, it should be 2018, not 2017.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
want = intnx('month', 
                     intnx('qtr', 
                                 intnx('month', run_month, 1, 'b'), 
                                 0, 'e'), 
                                         -1, 'b');
format want date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Jul 2017 06:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assign-last-month-value-to-previous-2-records/m-p/376308#M90313</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-16T06:56:27Z</dc:date>
    </item>
  </channel>
</rss>

