<?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: update master  table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358084#M84115</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34400"&gt;@Tal&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Looks like a slowly changing dimension type 2 (SCD2) to me. If so then I'd have the following columns in the table:&lt;/P&gt;
&lt;P&gt;valid_from_dt &amp;nbsp; (that's your current &lt;EM&gt;date&lt;/EM&gt; column)&lt;/P&gt;
&lt;P&gt;valid_to_dt &amp;nbsp; &amp;nbsp; &amp;nbsp; (set to something far in the future if current record, else date when expired and new current record added)&lt;/P&gt;
&lt;P&gt;change_current_ind &amp;nbsp; (1 if current record, else 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Primary key of table: {ID, valid_from_dt}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you've got SAS DI Studio then use transformation SCD Type 2. This one does the job for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without SAS DI Studio:&lt;/P&gt;
&lt;P&gt;1. SQL to determine in your daily increment table which ID's are brand new (inserts) and which one are a change (Update, Insert)&lt;/P&gt;
&lt;P&gt;2. Update of all records in master where ID with a change (= valid_to_dt set to date of your increment table, change_current_ind set to 0)&lt;/P&gt;
&lt;P&gt;3. Insert of all new and changed record from increment table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What about deletes? Does that ever happen? If so then you'd need another delta file with the deletes (just ID's) used to expire records in your master (= update of valid_to_dt)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your transaction data set got full volumes then a delete would be all ID's which exist in Master but don't exist in transaction DS.&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2017 01:31:44 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-05-12T01:31:44Z</dc:date>
    <item>
      <title>update master  table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358081#M84113</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;
&lt;P&gt;I have a master table which gets&amp;nbsp; updated&amp;nbsp; by daily SAS datasets.&lt;/P&gt;
&lt;P&gt;a) if the record&amp;nbsp; from the&amp;nbsp; daily&amp;nbsp; table is new&amp;nbsp; then simply append it to the master table&lt;/P&gt;
&lt;P&gt;b) if the record exists(no changes)&amp;nbsp; in the master then do nothing to it&lt;/P&gt;
&lt;P&gt;c)if the clientt exists in the master but he has some&amp;nbsp; updates in the&amp;nbsp; daily&amp;nbsp; file then append&amp;nbsp; his new reocrd to the master and also update the Date field of his previous record with the current date.&lt;/P&gt;
&lt;P&gt;In other words after the appending only clients&amp;nbsp; whose two last records in the master table&amp;nbsp;&amp;nbsp;&amp;nbsp; have missing date need to be updated(the Date field&amp;nbsp; of his second last record)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached samles&amp;nbsp; of how&amp;nbsp; table need to look like&lt;/P&gt;
&lt;P&gt;Tried&amp;nbsp; with last.id and&amp;nbsp;&amp;nbsp; first.id but&amp;nbsp; got stuck. Any hints&amp;nbsp; please?&lt;/P&gt;
&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 00:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358081#M84113</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2017-05-12T00:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: update master  table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358084#M84115</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34400"&gt;@Tal&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Looks like a slowly changing dimension type 2 (SCD2) to me. If so then I'd have the following columns in the table:&lt;/P&gt;
&lt;P&gt;valid_from_dt &amp;nbsp; (that's your current &lt;EM&gt;date&lt;/EM&gt; column)&lt;/P&gt;
&lt;P&gt;valid_to_dt &amp;nbsp; &amp;nbsp; &amp;nbsp; (set to something far in the future if current record, else date when expired and new current record added)&lt;/P&gt;
&lt;P&gt;change_current_ind &amp;nbsp; (1 if current record, else 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Primary key of table: {ID, valid_from_dt}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you've got SAS DI Studio then use transformation SCD Type 2. This one does the job for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without SAS DI Studio:&lt;/P&gt;
&lt;P&gt;1. SQL to determine in your daily increment table which ID's are brand new (inserts) and which one are a change (Update, Insert)&lt;/P&gt;
&lt;P&gt;2. Update of all records in master where ID with a change (= valid_to_dt set to date of your increment table, change_current_ind set to 0)&lt;/P&gt;
&lt;P&gt;3. Insert of all new and changed record from increment table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What about deletes? Does that ever happen? If so then you'd need another delta file with the deletes (just ID's) used to expire records in your master (= update of valid_to_dt)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your transaction data set got full volumes then a delete would be all ID's which exist in Master but don't exist in transaction DS.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 01:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358084#M84115</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-05-12T01:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: update master  table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358089#M84117</link>
      <description>Thx Patrick&lt;BR /&gt;I can get the records (A) from the daily file which are brand new and those with changes. So are you saying i can left join the master with (A)  and flag it with "new" and "existing" and if its existing than set the date to current and then simply append (A) to the master?</description>
      <pubDate>Fri, 12 May 2017 02:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358089#M84117</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2017-05-12T02:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: update master  table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358090#M84118</link>
      <description>In fact flag the master with "existing" only and update the date to current and then append (A) to the master table?</description>
      <pubDate>Fri, 12 May 2017 02:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358090#M84118</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2017-05-12T02:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: update master  table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358141#M84132</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34400"&gt;@Tal&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;So are you saying i can left join the master with (A) and flag it with "new" and "existing" and if its existing than set the date to current and then simply append (A) to the master&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;From what you've wrote initially you'll also have records in (A) which are identical with master and for these you can't just update the date in master and you need also to exclude these for Insert.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;(A) left join Master over ID where Master.Change_Current_Ind=1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- No match: New Record&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- Match:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;- if difference in one of the other columns under change tracking then Update Record&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;- if all columns under change tracking identical then "throw away".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- Update&amp;nbsp;Master with (A) where Master.ID=A.ID and Master.Change_Current_Ind=1 and A.&amp;lt;record_type&amp;gt;=&amp;lt;update&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set valid_to_dt to current date (data date of table A)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set change_current_ind=0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- Append (Insert) all records from (A) where A.&amp;lt;record_type&amp;gt; in (&amp;lt;new&amp;gt;,&amp;lt;update&amp;gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; valid_from_dt=&amp;lt;data date of table A&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; valid_to_dt=&amp;lt;date in far future&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; change_current_ind=1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does that make sense?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 06:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-master-table/m-p/358141#M84132</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-05-12T06:06:18Z</dc:date>
    </item>
  </channel>
</rss>

