<?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: Retaining Dates Against Transactions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648384#M194205</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expected output would have an additional column called True_Acquisition_Date and for the example above, all values would be 01JAN2014.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Sun, 17 May 2020 11:34:31 GMT</pubDate>
    <dc:creator>Baljit</dc:creator>
    <dc:date>2020-05-17T11:34:31Z</dc:date>
    <item>
      <title>Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648379#M194201</link>
      <description>&lt;P&gt;I have a dataset that contains a large number of customer IDs, a previous customer ID and a variable that represents the first acquisition date. Occasionally the customer ID is changed &amp;nbsp;and the value of previous customer ID is updated accordingly. This can happen multiple times and unfortunately, each time this happens the first acquisition date is updated to the date of the ID change and is not carried over.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Dataset Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Customer_ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Previous_Customer_ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; First_Acquisition_Date&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A103420830 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN2014&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B100453820 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A103420830 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2015&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C293099201 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B100453820 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to retain the true first date of acquisition against these ID changes but I am having some difficulties dealing with more than one ID change. Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Sun, 17 May 2020 10:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648379#M194201</guid>
      <dc:creator>Baljit</dc:creator>
      <dc:date>2020-05-17T10:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648382#M194203</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329334"&gt;@Baljit&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please specify what should be the expected output?&lt;/P&gt;
&lt;P&gt;Would something like this be convenient?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	retain First_Acquisition_Date2;
	format First_Acquisition_Date2 date9.;
	if missing(Previous_Customer_ID) then First_Acquisition_Date2=First_Acquisition_Date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Sun, 17 May 2020 11:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648382#M194203</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-17T11:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648383#M194204</link>
      <description>&lt;P&gt;Hi, The expected output is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Customer_ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Previous_Customer_ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; First_Acquisition_Date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TRUE_ACQUISITION_DATE&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A103420830 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN2014&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B100453820 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A103420830 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2014&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C293099201 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B100453820 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN2014&lt;/P&gt;</description>
      <pubDate>Sun, 17 May 2020 11:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648383#M194204</guid>
      <dc:creator>Baljit</dc:creator>
      <dc:date>2020-05-17T11:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648384#M194205</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expected output would have an additional column called True_Acquisition_Date and for the example above, all values would be 01JAN2014.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Sun, 17 May 2020 11:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648384#M194205</guid>
      <dc:creator>Baljit</dc:creator>
      <dc:date>2020-05-17T11:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648385#M194206</link>
      <description>That would be great and it is something I have tried, but in reality the data doesn't come in order of customer and previous customer id. Do you know how I could order it like this?</description>
      <pubDate>Sun, 17 May 2020 11:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648385#M194206</guid>
      <dc:creator>Baljit</dc:creator>
      <dc:date>2020-05-17T11:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648389#M194210</link>
      <description>&lt;P&gt;The data represent links in a transactional path.&amp;nbsp; You can store links data in a HASH object and traverse the HASH through the links to the head of the path, which would have the sole first date.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data have;
length Customer_ID  Previous_Customer_ID $10 First_Acquisition_Date 8;
input 
Customer_ID Previous_Customer_ID First_Acquisition_Date: date9.;
format First_Acquisition_Date date9.;
datalines;
A103420830  .            01JAN2014
B100453820  A103420830   01JAN2015
C293099201  B100453820   01JAN2016
;

data want;
  if _n_ = 0 then set have;

  if _n_ = 1 then do;
    declare hash paths(dataset:'have');
    paths.defineKey('Customer_ID');
    paths.defineData('Previous_Customer_ID', 'First_Acquisition_Date');
    paths.defineDone();
  end;

  set have;

  _H1 = First_Acquisition_Date;
  _H2 = Previous_Customer_ID;

  do _index = 1 to 1000 until (paths.find(key:Previous_Customer_ID) ne 0);
  end;

  if _index = &amp;gt; 1000 then do;
    put 'ERROR: Excessive path length or data loop' Customer_ID=;
    True_Acquisition_Date = .;
  end;
  else do;
    True_Acquisition_Date = First_Acquisition_Date;
  end;

  steps = _index - 1;
  First_Acquisition_Date = _H1;
  Previous_Customer_ID = _H2;

  attrib True_Acquisition_Date format=date9.;

  drop _:;
run;&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="paths.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39538i1B1623FB43AE187F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="paths.png" alt="paths.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 15:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648389#M194210</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-18T15:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648391#M194211</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329334"&gt;@Baljit&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, you need to use a HASH object.&lt;/P&gt;
&lt;P&gt;Please have a look at the following thread, which is exactly the same issue:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Specifying-the-observation-as-in-same-group/m-p/647741#M193888" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Specifying-the-observation-as-in-same-group/m-p/647741#M193888&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 May 2020 12:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648391#M194211</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-17T12:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648400#M194213</link>
      <description>&lt;P&gt;Here is the application of the method described in the thread (link above) to your use case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/******************************************************/
/** MACRO (source: cf. link above)					 **/
/******************************************************/

%macro SubGraphs(arcs,from=from,to=to,out=Clusters,exp=8);
	data _null_;
		if 0 then set &amp;amp;arcs(keep=&amp;amp;from rename=(&amp;amp;from=node)); /* get node data type */
		length clust 8;
		declare hash nodes(hashexp:&amp;amp;exp);
		nodes.defineKey('node');
		nodes.defineData('node', 'clust');
		nodes.defineDone();
		declare hiter nodeList('nodes');

		do newClust = 1 by 1 while(not endLoop);
			set &amp;amp;arcs end=endLoop;
			call missing(clust); node = &amp;amp;from;
			if 0^=nodes.find() then nodes.add(); 
			fromClust = clust; 
			call missing(clust); node = &amp;amp;to;
			if 0^=nodes.find() then nodes.add(); 
			toClust = clust;
			if n(fromClust, toClust) = 0 then do;
				nodes.replace(key:&amp;amp;from, data:&amp;amp;from, data:newClust);
				nodes.replace(key:&amp;amp;to, data:&amp;amp;to, data:newClust);
			end;
			else if missing(toClust) then 
				nodes.replace(key:&amp;amp;to, data:&amp;amp;to, data:fromClust);
			else if missing(fromClust) then 
				nodes.replace(key:&amp;amp;from, data:&amp;amp;from, data:toClust);
			else if fromClust ne toClust then do;
				rc = nodeList.first();
				do while (rc = 0);
					if clust = fromClust then 
						nodes.replace(key:node, data:node, data:toClust);
					rc = nodeList.next();
				end;
			end;
		end;
		nodes.output(dataset:"&amp;amp;out");
		stop;
	run;
%mend SubGraphs;

/******************************************************/

data have;
	length Customer_ID  Previous_Customer_ID $10 First_Acquisition_Date 8;
	input Customer_ID Previous_Customer_ID First_Acquisition_Date: date9.;
	format First_Acquisition_Date date9.;
	datalines;
A103420830  .            01JAN2014
F293099201  E100453820   01JAN2019
B100453820  A103420830   01JAN2015
C293099201  B100453820   01JAN2016
D103420830  .            01JAN2017
E100453820  D103420830   01JAN2018
;

data have2;
	set have;
	if missing(Previous_Customer_ID) then Previous_Customer_ID=Customer_ID;
	_numobs+1;
run;

%SubGraphs(have2,from=Customer_ID,to=Previous_Customer_ID,out=ref,exp=8);

proc sql;
	create table have3 as
	select a.*, b.clust
	from have2 as a left join ref as b
	on a.Customer_ID = b.node
	order by clust, First_Acquisition_Date;
run;

data have4;
	set have3;
	by clust;
	retain First_Acquisition_Date2;
	format First_Acquisition_Date2 date9.;
	if first.clust then do;
		First_Acquisition_Date2 = First_Acquisition_Date;
		call missing (Previous_Customer_ID);
	end;
run;

proc sort data=have4 out=want (drop=_: clust);
	by _numobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 May 2020 13:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648400#M194213</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-17T13:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining Dates Against Transactions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648526#M194294</link>
      <description>Can you post more data and the OUTPUT you are looking for ?</description>
      <pubDate>Mon, 18 May 2020 12:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-Dates-Against-Transactions/m-p/648526#M194294</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-18T12:00:34Z</dc:date>
    </item>
  </channel>
</rss>

