<?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: DI Studio - Holding Value Across Rows in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303976#M8631</link>
    <description>Resort your data by Id descending valid_from_dt. &lt;BR /&gt;Use retain for bot from ant to dt.&lt;BR /&gt;And then assign a new to dt with "previous" from dt-1 when appropriate. &lt;BR /&gt;Another crazy idea is the set all high dates to missing and then process the data through the SCD Type 2 Loader.</description>
    <pubDate>Wed, 12 Oct 2016 08:19:25 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-10-12T08:19:25Z</dc:date>
    <item>
      <title>DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303835#M8627</link>
      <description>&lt;P&gt;I need to do some clean-up on a few dim tables in our warehouse. It looks like our two columns that have the 'valid from date' and 'valide to date', which allow us to find the current record in a set of historical records, were not loaded correctly some time ago.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, we may have a record like follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Valid from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Valid to&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JUN2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JAN5999&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JAN2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JAN5999&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JUN2012&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JAN5999&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16AUG2014&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JAN5999&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01JAN2010&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30JUL2012&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01DEC2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0!JAN5999&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Clearly in each of these cases, only one record should have a 'Valid To' value of 01JAN5999....know we've got to fix it. I hope I made it clear in the example that it varies the number of records an ID may have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking if I could sort the the columns and retain the 'Valid From' record of the previous row, subtract 1 from the date, then I could have the correct 'Valid To' date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can this be done? Am I on the right path, or is there another approach?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 17:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303835#M8627</guid>
      <dc:creator>jwhite</dc:creator>
      <dc:date>2016-10-11T17:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303869#M8628</link>
      <description>&lt;P&gt;I think it sounds like a&amp;nbsp;feasible approach.&lt;/P&gt;
&lt;P&gt;Unless your data is huge. Then you might want o filter out the rows with high date, and&amp;nbsp;possible whole id groups, fix the necessary records separately, and do a table update/modify by.&lt;/P&gt;
&lt;P&gt;Just be aware that processing your data this way, indexes &amp;amp;&amp;nbsp;constraints will vanish, so you need to&amp;nbsp;apply them to your fixed data.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 19:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303869#M8628</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-11T19:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303882#M8629</link>
      <description>&lt;P&gt;Thanks, but how do I retain the value from one row to then do a -1 day expression on the next to get the new close date?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 20:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303882#M8629</guid>
      <dc:creator>jwhite</dc:creator>
      <dc:date>2016-10-11T20:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303909#M8630</link>
      <description>&lt;P&gt;Assuming the valid from dates are correct and you don't have the same value more than once per ID then below code gives you the logic for re-alignment.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input id (Valid_from_dttm Valid_to_dttm) (:date9.);
  format Valid_from_dttm Valid_to_dttm date9.;
  datalines;
1 01JUN2007 01JAN5999
1 01JAN2004 01JAN5999
4 01JUN2012 01JAN5999
4 16AUG2014 01JAN5999
4 01JAN2010 30JUL2012
4 01DEC2013 01JAN5999
;
run;

proc sort data=have out=have_sorted;
  by id Valid_from_dttm;
run;

data updates;
  set have_sorted;
  by id;
  format Valid_to_dttm_REALIGNED date9.;
  if not last.id then
    do;
      _ind=_n_+1;
      set want 
        ( 
        keep=Valid_from_dttm 
        rename=(Valid_from_dttm=_Valid_from_dttm)
        )
        point=_ind
        ;

      if Valid_to_dttm&amp;gt;_Valid_from_dttm then 
        do;
          Valid_to_dttm_REALIGNED=_Valid_from_dttm-1;
          output;
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your data is stored in a data base and you'r dealing with large data volumes then I would implement the logic directly in-database (eg. using analytics functions).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you can't re-construct are cases where a record had been expired but then a month later got&amp;nbsp;re-activated (if that's possible with your data). So something like below couldn't get reconstructed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 01JUN2004 01DEC2006
1 01JAN2007 01JAN5999&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 01:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303909#M8630</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-12T01:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303976#M8631</link>
      <description>Resort your data by Id descending valid_from_dt. &lt;BR /&gt;Use retain for bot from ant to dt.&lt;BR /&gt;And then assign a new to dt with "previous" from dt-1 when appropriate. &lt;BR /&gt;Another crazy idea is the set all high dates to missing and then process the data through the SCD Type 2 Loader.</description>
      <pubDate>Wed, 12 Oct 2016 08:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/303976#M8631</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-12T08:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/304671#M8673</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick﻿&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually blanking out all the values in that value_to_date column, then running through the SCD Type 2 loader did the trick.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 14:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/304671#M8673</guid>
      <dc:creator>jwhite</dc:creator>
      <dc:date>2016-10-14T14:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/304676#M8674</link>
      <description>&lt;P&gt;Sounds like a "hack". So using this approach you didn't create new records? And it really re-aligned all values also historical ones?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 14:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/304676#M8674</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-14T14:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio - Holding Value Across Rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/304679#M8675</link>
      <description>&lt;P&gt;It did not create any new records, but did realign the open and close dates for a given ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We also had a few cases where there would only be a singular record (ID) but was closed. This should be open so that each ID has an open record. It opened those cases with the '01JAN5999' date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feared it may create new records as well, but was pleased to see it didn't.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 14:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-Holding-Value-Across-Rows/m-p/304679#M8675</guid>
      <dc:creator>jwhite</dc:creator>
      <dc:date>2016-10-14T14:19:14Z</dc:date>
    </item>
  </channel>
</rss>

