<?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: How to retrieve parent-child in a &amp;quot;chain&amp;quot; of relationships without using reflexing joi in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326137#M62298</link>
    <description>&lt;P&gt;So the solution I provided doesn't work for you?&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jan 2017 21:46:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-01-19T21:46:16Z</dc:date>
    <item>
      <title>How to retrieve parent-child in a "chain" of relationships without using reflexing joins?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326097#M62287</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a dataset with three columns with this kind of information:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="658"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;OBS&lt;/TD&gt;
&lt;TD width="111"&gt;DATE&lt;/TD&gt;
&lt;TD width="354"&gt;CLIENT_ID&lt;/TD&gt;
&lt;TD width="129"&gt;OLD_CLIENT_ID&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;27-Sep-16&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;27-Sep-16&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;17-Jun-16&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;10-Sep-16&lt;/TD&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;5-Mar-16&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where "date" column is the date where some client&amp;nbsp;has made a change in his account id, and the other columns are the respective values at that moment.&lt;/P&gt;
&lt;P&gt;As you can see in the example dataset posted, many (and unknown) number of relationships could exist in the data history. For example, the client&amp;nbsp;"10" was before client&amp;nbsp;"6" (obs 1) but before was client&amp;nbsp;"4" (obs 3) and before of that was client&amp;nbsp;"2".&lt;/P&gt;
&lt;P&gt;Therefore, what I want is a final dataset with the client_id-old_client_id pairs taking account of what was said before, which will be like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="315"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;OBS&lt;/TD&gt;
&lt;TD width="75"&gt;DATE&lt;/TD&gt;
&lt;TD width="80"&gt;CLIENT_ID&lt;/TD&gt;
&lt;TD width="121"&gt;OLD_CLIENT_ID&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;1&lt;/TD&gt;
&lt;TD width="75"&gt;27-Sep-16&lt;/TD&gt;
&lt;TD width="80"&gt;10&lt;/TD&gt;
&lt;TD width="121"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;2&lt;/TD&gt;
&lt;TD width="75"&gt;17-Jun-16&lt;/TD&gt;
&lt;TD width="80"&gt;10&lt;/TD&gt;
&lt;TD width="121"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;3&lt;/TD&gt;
&lt;TD width="75"&gt;5-Mar-16&lt;/TD&gt;
&lt;TD width="80"&gt;10&lt;/TD&gt;
&lt;TD width="121"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;4&lt;/TD&gt;
&lt;TD width="75"&gt;27-Sep-16&lt;/TD&gt;
&lt;TD width="80"&gt;7&lt;/TD&gt;
&lt;TD width="121"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;5&lt;/TD&gt;
&lt;TD width="75"&gt;10-Sep-16&lt;/TD&gt;
&lt;TD width="80"&gt;9&lt;/TD&gt;
&lt;TD width="121"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset has ~ 4.000.000 obs.&lt;/P&gt;
&lt;P&gt;There is no other variable to identify the client uniquely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to accomplish this without using reflexive joins? As I said, number of relationships are unknown so making reflexive joins could be worst-performing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 19:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326097#M62287</guid>
      <dc:creator>lmignone</dc:creator>
      <dc:date>2017-01-19T19:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve parent-child in a "chain" of relationships without using reflexing joi</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326118#M62293</link>
      <description>&lt;P&gt;How is this question different from your previous (solved) question&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-the-last-value-in-a-quot-chain-quot-of/m-p/301260#M60593" target="_self"&gt;https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-the-last-value-in-a-quot-chain-quot-of/m-p/301260#M60593&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 20:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326118#M62293</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-01-19T20:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve parent-child in a "chain" of relationships without using reflexing joi</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326119#M62294</link>
      <description>&lt;P&gt;Hi PGStats,&lt;/P&gt;
&lt;P&gt;the expected result is not the same, as the output of the solved answer were 3 observations, meanwhile, for this question, the expected output has to got 5 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 20:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326119#M62294</guid>
      <dc:creator>lmignone</dc:creator>
      <dc:date>2017-01-19T20:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve parent-child in a "chain" of relationships without using reflexing joi</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326120#M62295</link>
      <description>&lt;P&gt;There are a couple of solved questions on here with different HASH solutions to this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is based on a macro written by PGStats. You didn't show what you want as your final results, but this will get you closer, if its not what you want as an end result. Note the last parameter controls how 'deep' the search goes so you do need some idea or set it to an arbitrarily high number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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;
informat obs 8. date date9.;
format date date9.;
input  OBS	DATE	CLIENT_ID	OLD_CLIENT_ID;
cards;
1	27Sep16	10	6
2	17Jun16	10	4
3	5Mar16	10	2
4	27Sep16	7	5
5	10Sep16	9	8
;
run;

%SubGraphs(have, from=old_client_id, to=client_id, out=want,exp=4);

proc sort data=want;
by clust node;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jan 2017 20:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326120#M62295</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-19T20:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve parent-child in a "chain" of relationships without using reflexing joi</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326123#M62296</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8712"&gt;@lmignone&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi PGStats,&lt;/P&gt;
&lt;P&gt;the expected result is not the same, as the output of the solved answer were 3 observations, meanwhile, for this question, the expected output has to got 5 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm confused. How does the 3/5 change the situation?&lt;/P&gt;
&lt;P&gt;Those solutions don't seem dependent on the depth of the linkage. Can you explain with an example of how it doesn't work?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 20:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326123#M62296</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-19T20:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve parent-child in a "chain" of relationships without using reflexing joi</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326128#M62297</link>
      <description>&lt;P&gt;In the previous solution, the expected output was just the oldest client id for each client_id:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="594"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="111"&gt;OBS&lt;/TD&gt;
&lt;TD width="354"&gt;
&lt;P&gt;CLIENT_ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="129"&gt;OLD_CLIENT_ID&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Meanwhile, in this question I'm asking for all the relationships that, for example, client_id 10 has in the input data. The expected output is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="315"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;OBS&lt;/TD&gt;
&lt;TD width="75"&gt;DATE&lt;/TD&gt;
&lt;TD width="80"&gt;CLIENT_ID&lt;/TD&gt;
&lt;TD width="121"&gt;OLD_CLIENT_ID&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;1&lt;/TD&gt;
&lt;TD width="75"&gt;27-Sep-16&lt;/TD&gt;
&lt;TD width="80"&gt;10&lt;/TD&gt;
&lt;TD width="121"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;2&lt;/TD&gt;
&lt;TD width="75"&gt;17-Jun-16&lt;/TD&gt;
&lt;TD width="80"&gt;10&lt;/TD&gt;
&lt;TD width="121"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;3&lt;/TD&gt;
&lt;TD width="75"&gt;5-Mar-16&lt;/TD&gt;
&lt;TD width="80"&gt;10&lt;/TD&gt;
&lt;TD width="121"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;4&lt;/TD&gt;
&lt;TD width="75"&gt;27-Sep-16&lt;/TD&gt;
&lt;TD width="80"&gt;7&lt;/TD&gt;
&lt;TD width="121"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="39"&gt;5&lt;/TD&gt;
&lt;TD width="75"&gt;10-Sep-16&lt;/TD&gt;
&lt;TD width="80"&gt;9&lt;/TD&gt;
&lt;TD width="121"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that I don't need the relationship between 6-4 or between 4-2, as those ones has a newer client ID (10).&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 21:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326128#M62297</guid>
      <dc:creator>lmignone</dc:creator>
      <dc:date>2017-01-19T21:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve parent-child in a "chain" of relationships without using reflexing joi</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326137#M62298</link>
      <description>&lt;P&gt;So the solution I provided doesn't work for you?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 21:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326137#M62298</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-19T21:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve parent-child in a "chain" of relationships without using reflexing joi</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326246#M62308</link>
      <description>&lt;P&gt;It needs a further transformation in order to reach the desired result, but it works...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Reeza!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:17:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retrieve-parent-child-in-a-quot-chain-quot-of/m-p/326246#M62308</guid>
      <dc:creator>lmignone</dc:creator>
      <dc:date>2017-01-20T13:17:43Z</dc:date>
    </item>
  </channel>
</rss>

