<?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: Attach recent records back to the original in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172305#M33123</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Keshan.&lt;/P&gt;&lt;P&gt;In my case, the current month means the most recent month on book. However, I think your code provide solution to another case scenario. I will save it for later.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Nov 2014 04:03:17 GMT</pubDate>
    <dc:creator>jiangmi</dc:creator>
    <dc:date>2014-11-17T04:03:17Z</dc:date>
    <item>
      <title>Attach recent records back to the original</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172301#M33119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input acct$ month sale;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;A 20141101 90&lt;/P&gt;&lt;P&gt;A 20141001 88&lt;/P&gt;&lt;P&gt;A 20140901 85&lt;/P&gt;&lt;P&gt;B 20141001 84&lt;/P&gt;&lt;P&gt;B 20140901 80&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input acct$ month sale sale_now sale_prior;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;A 20141101 90 90 88&lt;/P&gt;&lt;P&gt;A 20141001 88 90 88&lt;/P&gt;&lt;P&gt;A 20140901 85 90 88&lt;/P&gt;&lt;P&gt;B 20141001 84 . 84&lt;/P&gt;&lt;P&gt;B 20140901 80 . 84&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I want to create two new columns and attach the current month (20141101) sale and the month before (20141001) to the existing records. Right now, I can get my results with some long codes. I believe there are better ways and I want to learn it. Thank&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, the current month and the month before will always be different every month. Some acct may not have data on current month (acct B in this case). I am looking for something that works dynamically.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Nov 2014 19:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172301#M33119</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2014-11-14T19:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Attach recent records back to the original</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172302#M33120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select a.*,b.sale_now,c.sale_prior from have a&lt;/P&gt;&lt;P&gt;left join (select acct,sale as sale_now from have group acct&lt;/P&gt;&lt;P&gt;having month(month)=max(month(month))) b&lt;/P&gt;&lt;P&gt;on a.acct=b.acct&lt;/P&gt;&lt;P&gt;left join&lt;/P&gt;&lt;P&gt;(select acct,sale as sale_prior from have group acct&lt;/P&gt;&lt;P&gt;having month(month)=max(month(month))-1) c&lt;/P&gt;&lt;P&gt;on a.acct=c.acct; &lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Nov 2014 20:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172302#M33120</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-11-14T20:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Attach recent records back to the original</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172303#M33121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. This is a better solution to my situation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 03:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172303#M33121</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2014-11-15T03:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Attach recent records back to the original</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172304#M33122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;the current month, you mean &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;the current month in reality (today - Nov)?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt; 

data have;
input acct$ month : yymmdd10. sale;
format month&amp;nbsp; yymmdd10.;
datalines;
A 20141101 90
A 20141001 88
A 20140901 85
B 20141001 84
B 20140901 80
;
run;
proc sql;
create table want as
 select *,(select sale from have where acct=a.acct and month=intnx('month',"&amp;amp;sysdate"d,0,'b'))&amp;nbsp; as sale_now ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select sale from have where acct=a.acct and month=intnx('month',"&amp;amp;sysdate"d,-1,'b'))&amp;nbsp; as&amp;nbsp; sale_prior
&amp;nbsp; from have as a;
quit; &lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.727272033691406px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Xia Keshan&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 08:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172304#M33122</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-15T08:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Attach recent records back to the original</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172305#M33123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Keshan.&lt;/P&gt;&lt;P&gt;In my case, the current month means the most recent month on book. However, I think your code provide solution to another case scenario. I will save it for later.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Nov 2014 04:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attach-recent-records-back-to-the-original/m-p/172305#M33123</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2014-11-17T04:03:17Z</dc:date>
    </item>
  </channel>
</rss>

