<?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: Append and overwrite a second dataset to the base in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768696#M243841</link>
    <description>You always start with 12 observations and always want to replace the last 3 ?&lt;BR /&gt;No. There are more month/year data further up the table but will receive last three months so need to keep the historical data while append &amp;amp; overwrite the latest three months.&lt;BR /&gt;&lt;BR /&gt;Your data has no identifiable order to it?  No year variable?  No ordered value for month like a value from 1 to 12?&lt;BR /&gt;The data is currently order by month.&lt;BR /&gt;&lt;BR /&gt;I guess it's something more like this &lt;BR /&gt;Month	Values&lt;BR /&gt;Aug-19	100&lt;BR /&gt;Sep-19	100&lt;BR /&gt;Oct-19	100&lt;BR /&gt;Nov-19	100&lt;BR /&gt;Dec-19	100&lt;BR /&gt;Jan-20	100&lt;BR /&gt;Feb-20	100&lt;BR /&gt;Mar-20	100&lt;BR /&gt;Apr-20	100&lt;BR /&gt;May-20	100&lt;BR /&gt;Jun-20	100&lt;BR /&gt;Jul-20	100&lt;BR /&gt;Aug-20	100&lt;BR /&gt;Sep-20	100&lt;BR /&gt;Oct-20	200&lt;BR /&gt;Nov-20	200&lt;BR /&gt;Dec-20	200&lt;BR /&gt;</description>
    <pubDate>Tue, 21 Sep 2021 03:57:08 GMT</pubDate>
    <dc:creator>ywon111</dc:creator>
    <dc:date>2021-09-21T03:57:08Z</dc:date>
    <item>
      <title>Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768686#M243835</link>
      <description>&lt;P&gt;Hi, I receive a new dataset each month and hoping to append this to the base dataset and overwrite the latest three months. What is the best way to code this? Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Base:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 108pt;" border="0" width="144" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD width="72" height="19" style="height: 14.25pt; width: 54pt;"&gt;Month&lt;/TD&gt;
&lt;TD width="72" style="width: 54pt;"&gt;Values&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Jan&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Feb&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Mar&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Apr&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;May&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Jun&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Jul&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Aug&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Sep&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Oct&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Nov&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Dec&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second dataset:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 108pt;" border="0" width="144" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD width="72" height="19" style="height: 14.25pt; width: 54pt;"&gt;Month&lt;/TD&gt;
&lt;TD width="72" style="width: 54pt;"&gt;Values&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Oct&lt;/TD&gt;
&lt;TD align="right"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Nov&lt;/TD&gt;
&lt;TD align="right"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Dec&lt;/TD&gt;
&lt;TD align="right"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I want&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 108pt;" border="0" width="144" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD width="72" height="19" style="height: 14.25pt; width: 54pt;"&gt;Month&lt;/TD&gt;
&lt;TD width="72" style="width: 54pt;"&gt;Values&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Jan&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Feb&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Mar&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Apr&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;May&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Jun&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Jul&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Aug&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Sep&lt;/TD&gt;
&lt;TD align="right"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Oct&lt;/TD&gt;
&lt;TD align="right"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Nov&lt;/TD&gt;
&lt;TD align="right"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.25pt;"&gt;
&lt;TD height="19" style="height: 14.25pt;"&gt;Dec&lt;/TD&gt;
&lt;TD align="right"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 21 Sep 2021 00:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768686#M243835</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-09-21T00:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768695#M243840</link>
      <description>&lt;P&gt;Your question stretches the imagination in a few ways:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You always start with 12 observations and always want to replace the last 3 ??&lt;/LI&gt;
&lt;LI&gt;Your data has no identifiable order to it?&amp;nbsp; No year variable?&amp;nbsp; No ordered value for month like a value from 1 to 12?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The problem you state is easy:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set first (obs=9) second;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I sincerely believe the answer will change when I get more information about the actual form to the data.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 03:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768695#M243840</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-09-21T03:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768696#M243841</link>
      <description>You always start with 12 observations and always want to replace the last 3 ?&lt;BR /&gt;No. There are more month/year data further up the table but will receive last three months so need to keep the historical data while append &amp;amp; overwrite the latest three months.&lt;BR /&gt;&lt;BR /&gt;Your data has no identifiable order to it?  No year variable?  No ordered value for month like a value from 1 to 12?&lt;BR /&gt;The data is currently order by month.&lt;BR /&gt;&lt;BR /&gt;I guess it's something more like this &lt;BR /&gt;Month	Values&lt;BR /&gt;Aug-19	100&lt;BR /&gt;Sep-19	100&lt;BR /&gt;Oct-19	100&lt;BR /&gt;Nov-19	100&lt;BR /&gt;Dec-19	100&lt;BR /&gt;Jan-20	100&lt;BR /&gt;Feb-20	100&lt;BR /&gt;Mar-20	100&lt;BR /&gt;Apr-20	100&lt;BR /&gt;May-20	100&lt;BR /&gt;Jun-20	100&lt;BR /&gt;Jul-20	100&lt;BR /&gt;Aug-20	100&lt;BR /&gt;Sep-20	100&lt;BR /&gt;Oct-20	200&lt;BR /&gt;Nov-20	200&lt;BR /&gt;Dec-20	200&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Sep 2021 03:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768696#M243841</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-09-21T03:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768701#M243846</link>
      <description>&lt;P&gt;I'm still not convinced I have the entire picture.&amp;nbsp; But here's a way to address what is known so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set first obs=totalobs;
   if _n_ &amp;gt;= totalobs - 2 then set second;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One "feature" of this program:&amp;nbsp; it still works if FIRST contains 100 variables, but SECOND only contains 2 variables.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 04:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768701#M243846</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-09-21T04:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768709#M243852</link>
      <description>I get records of three quarters' worth of data (e.g. Jun20, Sep20 and Dec20) that needs to be appended and overwrite the base dataset which has historical data tracking from Jun96 plus other quarters except latest Dec20. The latest three quarters need to overwrite existing ones in base as the values there gets updated. &lt;BR /&gt;&lt;BR /&gt;Month Value&lt;BR /&gt;Jun19 100&lt;BR /&gt;Jun19 100&lt;BR /&gt;Sep19 100&lt;BR /&gt;Sep19 100&lt;BR /&gt;Sep19 100&lt;BR /&gt;Dec19 100&lt;BR /&gt;Dec19 100&lt;BR /&gt;Dec19 100&lt;BR /&gt;Dec19 100&lt;BR /&gt;Mar20 100&lt;BR /&gt;Mar20 100&lt;BR /&gt;Jun20 100&lt;BR /&gt;Sep20 100&lt;BR /&gt;Sep20 100&lt;BR /&gt;Sep20 100&lt;BR /&gt;Dec20 100&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Sep 2021 06:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768709#M243852</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-09-21T06:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768710#M243853</link>
      <description>&lt;P&gt;You need to be very precise here!&lt;/P&gt;
&lt;P&gt;1. Do these latest 3 quarters already exist in your base table? If YES then you want to UPDATE them with the new values, if NO then you want to INSERT (append) them into your base table.&lt;/P&gt;
&lt;P&gt;2. What does REPLACE mean? Are you asking to DELETE the oldest 3 months from your base table? Or is it something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does your data look like in your last sample with only one row per month? Or is your data more granular - and if so what's the key that uniquely identifies exactly one row of data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And last but not least: What are the data volumes? How many rows do you have in your real base table and your real transaction table?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 06:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768710#M243853</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-21T06:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768715#M243855</link>
      <description>&lt;P&gt;I guess you also have some kind of id value in the datasets.&lt;/P&gt;
&lt;P&gt;I would do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id month;
run;

proc sort data=trans;
by id month;
run;

data want;
merge
  have
  trans (
    in=t
    rename=(value=_value)
  )
;
by id month;
if t then value = _value;
drop _value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;New ID's and/or months will be added, existing ones updated.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 08:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768715#M243855</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-21T08:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768983#M243931</link>
      <description>Thanks it ran fine but it's missing one part. I receive data quarterly which contains the latest three quarters (e.g. Dec 2019, Mar 2020, Jun 2020), these numbers gets updated so it needs to be appended to the base and overwrite as it contains data from June 1999 to March 2020 (the Dec 2019 and Mar 2020 in base will need to be removed and overwritten with the newly updated data). Hope this makes sense...</description>
      <pubDate>Wed, 22 Sep 2021 00:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/768983#M243931</guid>
      <dc:creator>ywon111</dc:creator>
      <dc:date>2021-09-22T00:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Append and overwrite a second dataset to the base</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/769020#M243952</link>
      <description>&lt;P&gt;Applying my code to your original data (and omitting ID) like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x;
input month :monyy7. values;
format month yymmd7.;
datalines;
Jan2020	100
Feb2020	100
Mar2020	100
Apr2020	100
May2020	100
Jun2020	100
Jul2020	100
Aug2020	100
Sep2020	100
Oct2020	100
Nov2020	100
Dec2020	100
;

data trans;
infile datalines dlm="09"x;
input month :monyy7. values;
format month yymmd7.;
datalines;
Oct2020	200
Nov2020	200
Dec2020	200
;

proc sort data=have;
by month;
run;

proc sort data=trans;
by month;
run;

data want;
merge
  have
  trans (
    in=t
    rename=(values=_values)
  )
;
by month;
if t then values = _values;
drop _values;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;creates your intended result from your original question.&lt;/P&gt;
&lt;P&gt;If your requirement is different, post your data in usable form (data steps with datalines, see above) and show the expected result out of this.&lt;/P&gt;
&lt;P&gt;Use the "little running man" right next to this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;for posting your codes.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 07:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-and-overwrite-a-second-dataset-to-the-base/m-p/769020#M243952</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-22T07:00:21Z</dc:date>
    </item>
  </channel>
</rss>

