<?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: Creating a date delta (delta table/delta log) when updating dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708412#M217710</link>
    <description>&lt;P&gt;I came up with this not very elegant solution, but it seems to work. better solutions or comments on this one are highly appreciated.&lt;/P&gt;&lt;PRE&gt;proc sql;
* Added rows;
create table added as
select b.ID
     , b.date1 as valid_from
	 , '31dec9999'd as valid_to
     , b.amount
     , "A" as changetype 
 from have2 b
 left outer join have1 a
  on a.ID = b.ID 
  where a.ID = ''
;

* not changed rows;
create table noChange as
select a.ID
     , a.date1 as valid_from
	 , '31dec9999'd as valid_to
     , a.amount
     , "N" as changetype 
 from have1 a
 left outer join have2 b
  on a.ID = b.ID 
  where (b.ID = '') 
   or (a.amount=b.amount)
;

* modified rows;
create table modified_before as
select a.ID
     , a.date1 as valid_from
	 , b.date1 as valid_to
	 , a.amount
	 , "M" as changetype
  from have1 a
  inner join have2 b
  on a.ID = b.ID
  where a.amount^=b.amount;


create table modified_after as
select b.ID
     , b.date1 as valid_from
	 , '31dec9999'd as valid_to
	 , b.amount
	 , "M" as changetype
  from have1 a
  inner join have2 b
  on a.ID = b.ID
  where a.amount^=b.amount;
quit;

data test4;
set added noChange modified_before modified_after;
run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Dec 2020 11:24:11 GMT</pubDate>
    <dc:creator>LiEnBe</dc:creator>
    <dc:date>2020-12-28T11:24:11Z</dc:date>
    <item>
      <title>Creating a date delta (delta table/delta log) when updating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708399#M217702</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been using sas for a while for statistical and modelling purposes but am now venturing into a little more data wrangling than I am used to.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I receive data (as excel files) four times a year and would like to be able to create a dataset with history, so that I can go back and redo my calculations later.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done some datawork on the excel file and now have two datasets that looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have1;
   input ID:$3. date1:date9. amount:32.;
   format date1 date9.;
 datalines;
102 '02jun2020'd  163
103 '02jun2020'd  198
104 '02jun2020'd  155
;
run;

data have2;
   input ID:$3. date1:date9. amount:32.;
   format date1 date9.;
 datalines;
102 '14sep2020'd  163
103 '14sep2020'd  231
105 '14sep2020'd  116
;
run;

data want;
   input ID:$3. valid_from:date9. valid_to:date9. amount:32.;
   format valid_from valid_to date9.;
   datalines;
102 '02jun2020'd '31dec9999'd 163
103 '02jun2020'd '14sep2020'd 198
103 '14sep2020'd '31dec9999'd 231
104 '02jun2020'd '31dec9999'd 155
105 '14sep2020'd '31dec9999'd 116
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been looking at both the update statement and a little at sas macro programming, but have realized that I am a little out of clue as to where to start. Do any of you have an example or some resources I can look into? The valid to date can be blanc as well as having the max date.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.4&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 10:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708399#M217702</guid>
      <dc:creator>LiEnBe</dc:creator>
      <dc:date>2020-12-28T10:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date delta (delta table/delta log) when updating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708407#M217706</link>
      <description>&lt;P&gt;You have to explain the logic you want applied.&lt;/P&gt;
&lt;P&gt;To combine both datasets, you can use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   merge have1(rename= (date1 = valid_from)) have2(rename= (date1 = valid_to));
   by ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Dec 2020 11:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708407#M217706</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-28T11:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date delta (delta table/delta log) when updating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708412#M217710</link>
      <description>&lt;P&gt;I came up with this not very elegant solution, but it seems to work. better solutions or comments on this one are highly appreciated.&lt;/P&gt;&lt;PRE&gt;proc sql;
* Added rows;
create table added as
select b.ID
     , b.date1 as valid_from
	 , '31dec9999'd as valid_to
     , b.amount
     , "A" as changetype 
 from have2 b
 left outer join have1 a
  on a.ID = b.ID 
  where a.ID = ''
;

* not changed rows;
create table noChange as
select a.ID
     , a.date1 as valid_from
	 , '31dec9999'd as valid_to
     , a.amount
     , "N" as changetype 
 from have1 a
 left outer join have2 b
  on a.ID = b.ID 
  where (b.ID = '') 
   or (a.amount=b.amount)
;

* modified rows;
create table modified_before as
select a.ID
     , a.date1 as valid_from
	 , b.date1 as valid_to
	 , a.amount
	 , "M" as changetype
  from have1 a
  inner join have2 b
  on a.ID = b.ID
  where a.amount^=b.amount;


create table modified_after as
select b.ID
     , b.date1 as valid_from
	 , '31dec9999'd as valid_to
	 , b.amount
	 , "M" as changetype
  from have1 a
  inner join have2 b
  on a.ID = b.ID
  where a.amount^=b.amount;
quit;

data test4;
set added noChange modified_before modified_after;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Dec 2020 11:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708412#M217710</guid>
      <dc:creator>LiEnBe</dc:creator>
      <dc:date>2020-12-28T11:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a date delta (delta table/delta log) when updating dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708415#M217713</link>
      <description>&lt;P&gt;Sorry for not explaining.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you got what I wanted though. Thank you.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 11:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-date-delta-delta-table-delta-log-when-updating/m-p/708415#M217713</guid>
      <dc:creator>LiEnBe</dc:creator>
      <dc:date>2020-12-28T11:53:08Z</dc:date>
    </item>
  </channel>
</rss>

