<?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: joining with previous month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462377#M117715</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175837"&gt;@Myurathan&lt;/a&gt;&amp;nbsp; You could mark any of the responses as an accepted solution and extend the courtesy to the respondents who volunteer for free to contribute in the community.&amp;nbsp; This is the very least we can do.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 May 2018 14:51:30 GMT</pubDate>
    <dc:creator>MarkWik</dc:creator>
    <dc:date>2018-05-15T14:51:30Z</dc:date>
    <item>
      <title>joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462083#M117569</link>
      <description>&lt;P&gt;I have following table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="01.png" style="width: 387px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20512i7D47911507E6D9C0/image-size/large?v=v2&amp;amp;px=999" role="button" title="01.png" alt="01.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have previous month data joined to the table. something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="02.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20513i7BFE3692DE04D01F/image-size/large?v=v2&amp;amp;px=999" role="button" title="02.png" alt="02.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462083#M117569</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2018-05-14T15:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462091#M117576</link>
      <description>&lt;P&gt;I assume that you want this within values of ID (you did not state that though the example implies that).&lt;/P&gt;
&lt;P&gt;Are there by any chance other dates in Jan2018 for those ids?&lt;/P&gt;
&lt;P&gt;If not then this might get you started:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table want as
   select a.date, a.id, a.value_01, a.value_02
         ,b.date as Prv_date, b.value_01 as Prv_value_01
         , b.value_02 as Prv_value_02
   from have as a
        left join
        have as b
        on a.id=b.id
        and intnx('month',a.date,-1,'B') = intx('month',b.date,0,'B')
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;if you have dates for the same Id such as in Dec 2017 the Jan2018 will be linked to them as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462091#M117576</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-14T15:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462092#M117577</link>
      <description>&lt;P&gt;Where intnx('month', t1.date, 1, 'e') = t2.date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use INTNX to increment&amp;nbsp;the date to the last of the next month and see if it matches the date in table 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175837"&gt;@Myurathan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have following table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="01.png" style="width: 387px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20512i7D47911507E6D9C0/image-size/large?v=v2&amp;amp;px=999" role="button" title="01.png" alt="01.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to have previous month data joined to the table. something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="02.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20513i7BFE3692DE04D01F/image-size/large?v=v2&amp;amp;px=999" role="button" title="02.png" alt="02.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462092#M117577</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-14T15:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462097#M117578</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175837"&gt;@Myurathan&lt;/a&gt;&amp;nbsp;If you could paste your data as plain text, I could copy paste on to my sas and work on a solution. I am afraid i am too lazy to type from pics/screen shots. Just a request going forward in future. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462097#M117578</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-14T15:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462101#M117580</link>
      <description>data date_test;&lt;BR /&gt;input Date: date9. ID Value_01 Value_02;&lt;BR /&gt;format date date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;31Jan2018 001 1000 2000&lt;BR /&gt;31Jan2018 002 1500 2500&lt;BR /&gt;28Feb2018 001 5000 6000&lt;BR /&gt;28Feb2018 002 3000 5800&lt;BR /&gt;;&lt;BR /&gt;</description>
      <pubDate>Mon, 14 May 2018 15:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462101#M117580</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2018-05-14T15:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462120#M117590</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date_test;
input Date: date9. ID Value_01 Value_02;
format date date9.;
datalines;
31Jan2018 001 1000 2000
31Jan2018 002 1500 2500
28Feb2018 001 5000 6000
28Feb2018 002 3000 5800
;

proc sort data=date_test out=_date_test;
by id date;
run;

data want;
if _n_=1 then do;
if 0 then set _date_test;
if 0 then set _date_test(rename=(date=Prv_date value_01=prv_Value_01 Value_02=prv_Value_02));
 dcl hash H (dataset:'_date_test(rename=(date=Prv_date value_01=prv_Value_01 Value_02=prv_Value_02))') ;
   h.definekey  ("id",'Prv_date') ;
   h.definedata (all:'y') ;
   h.definedone () ;
end;
set _date_test;
by id;
if h.find(key:id,key: intnx('month',date,-1,'e'))=0 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 May 2018 16:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462120#M117590</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-14T16:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462151#M117606</link>
      <description>&lt;P&gt;If you have exactly one obs per id and month, then this will do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id date;
run;

data want;
set have;
by id;
format prv_date date9.;
prv_date = lag(date);
prv_value_01 = lag(value_01);
prv_value_02 = lag(value_02);
if first.id
then do;
  prv_date = .;
  prv_value_01 = .;
  prv_value_02 = .;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 May 2018 18:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462151#M117606</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-14T18:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: joining with previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462377#M117715</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175837"&gt;@Myurathan&lt;/a&gt;&amp;nbsp; You could mark any of the responses as an accepted solution and extend the courtesy to the respondents who volunteer for free to contribute in the community.&amp;nbsp; This is the very least we can do.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 14:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-with-previous-month/m-p/462377#M117715</guid>
      <dc:creator>MarkWik</dc:creator>
      <dc:date>2018-05-15T14:51:30Z</dc:date>
    </item>
  </channel>
</rss>

