<?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: Find all parents and children for each record. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951410#M45561</link>
    <description>Mind blown... thank you!</description>
    <pubDate>Wed, 20 Nov 2024 23:26:40 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2024-11-20T23:26:40Z</dc:date>
    <item>
      <title>Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951308#M45547</link>
      <description>&lt;P&gt;I'm stuck trying to go from this table:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;cid&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;parent_cid&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;e&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;f&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;g&lt;/TD&gt;&lt;TD&gt;f&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To this table:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;cid&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;sort_cid&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;sort_chain&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;level&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;1.1.1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;1.2.1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;1.2.2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;1.3.1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;1.1.1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;1.2.1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;1.2.2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;1.1.1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;1.2.1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;1.2.2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;1.1.1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;1.3.1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;e&lt;/TD&gt;&lt;TD&gt;e&lt;/TD&gt;&lt;TD&gt;2.1.1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;f&lt;/TD&gt;&lt;TD&gt;f&lt;/TD&gt;&lt;TD&gt;3.1.1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;f&lt;/TD&gt;&lt;TD&gt;g&lt;/TD&gt;&lt;TD&gt;3.2.1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;g&lt;/TD&gt;&lt;TD&gt;f&lt;/TD&gt;&lt;TD&gt;3.1.1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;g&lt;/TD&gt;&lt;TD&gt;g&lt;/TD&gt;&lt;TD&gt;3.2.1&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;In short, I want for every&amp;nbsp;&lt;STRONG&gt;cid&lt;/STRONG&gt; every&amp;nbsp;&lt;STRONG&gt;parent&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;and child&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;cid&lt;/STRONG&gt; in the 'chain' as &lt;STRONG&gt;sort_cid&lt;/STRONG&gt;. Next to that, for every sort_cid I need a dot-separated chain of numbers, to be able to sort the sort_cid in a Viya Dashboard. I also need to know which 'level' each sort_cid is, e.g. if it is the main parent (level 1) or it has two parents (level 3).&lt;/P&gt;&lt;P&gt;Any help would be much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 12:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951308#M45547</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-20T12:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951319#M45548</link>
      <description>&lt;P&gt;Why is level = 2 in the 4th obs?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 12:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951319#M45548</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-11-20T12:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951354#M45552</link>
      <description>&lt;P&gt;I do not get your output.&amp;nbsp; But here is a simple way you can load the parent/child pairs into a hash object and use that to generate a list of each person and which family and what level within they family they are.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input cid $	parent_cid $;
cards;
a	.
b	a
c	b
d	a
e	.
f	.
g	f
;

data want;
  set have ;
  where missing(parent_cid);
  family+1;
if _n_=1 then do;
  declare hash h(multidata:'yes',dataset:'have(where=(not missing(parent_cid)))');
  h.definekey('parent_cid');
  h.definedata('cid');
  h.definedone();
end;
 do generation=1 by 1 until(h.find());
    output;
    parent_cid=cid;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;              parent_
Obs    cid      cid      family    generation

 1      a                   1           1
 2      b        a          1           2
 3      c        b          1           3
 4      e                   2           1
 5      f                   3           1
 6      g        f          3           2

&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2024 15:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951354#M45552</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-20T15:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951361#M45553</link>
      <description>&lt;P&gt;Because a is the parent of d. So d is the child of a. Since a = level 1, then d = level 2. Another way to see it: b and d are siblings :). This can be deducted from level = 2.&lt;/P&gt;&lt;P&gt;What I want to achieve:&lt;BR /&gt;I want to use the level-column to put spaces in front of the cid (which in my real data is a company name), together with the sort_chain to sort the data in viya. My final result in Viya should look like this:&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;&amp;nbsp; b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;&lt;P&gt;&amp;nbsp; d&lt;/P&gt;&lt;P&gt;e&lt;/P&gt;&lt;P&gt;f&lt;/P&gt;&lt;P&gt;&amp;nbsp; g&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Viya I want to select a company (using cid), and then want to display the full company-chain to the user.&lt;/P&gt;&lt;P&gt;So if a user selects 'a', they should see this in Viya in a list table:&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;&amp;nbsp; b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;&lt;P&gt;&amp;nbsp; d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sort_chain is used to make sure the results are always displayed in this order.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 16:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951361#M45553</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-20T16:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951367#M45554</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for taking the time to help me out!&lt;/P&gt;&lt;P&gt;I have replied above to another comment to further explain my output (and why it is needed).&lt;/P&gt;&lt;P&gt;I have no experience with hash-objects, so I do not fully understand the workings of the code.&lt;/P&gt;&lt;P&gt;The output you have generates is a step in the right direction, but record [d a] is missing. I do not fully understand from the code why that would happen (unless a hash in SAS is the equivalent of a dictionary in Python? Then one cannot have duplicate keys).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this together with my other comment clarifies it a bit. I understand the output might be 'strange', but Viya is a strange program to work with, so sometimes unconventional tables must be loaded into it to create the output a user wants &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 16:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951367#M45554</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-20T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951385#M45557</link>
      <description>&lt;P&gt;I think my brain melted trying to understand the 'sort_chain' variable, but the following code produces the rest of them in the format you specified - I think I'm just not understanding how to derive sort_chain from this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards dsd truncover firstobs=1 dlm=',';
length cid parent_cid $1;
input cid parent_cid;
cards;
a,
b,a
c,b
d,a
e,
f,
g,f
;
run;

proc sql noprint;
create table c2num as
select 'fc2num' as fmtname length=8, 
'C' as type length=1, cid as start, monotonic() as label
from have;
quit;

data num2c (rename=(_start=start _label=label));
set c2num (rename=(start=_label label=_start));
fmtname='fnum2c';
type='N';
run;

data c2num;
set c2num end=last;
output;
n+1;
if last then do;
	start=' ';
	label=0;
	output;
	call symputx("ncids",n);
end;
drop n;
run;

proc format cntlin=c2num; run;
proc format cntlin=num2c; run;

data want;
set have (rename=(cid=_CID parent_CID=_PC)) end=last;
array nparents {0:&amp;amp;ncids} _temporary_ (%eval(&amp;amp;ncids+1)*0);
array p {&amp;amp;ncids} _temporary_;
nparents[put(_CID,$fc2num.)*1]+nparents[put(_PC,$fc2num.)*1]+1;
p[put(_CID,$fc2num.)*1]=put(_PC,$fc2num.)*1;
if last then do;
	do i=1 to dim(p);
		cid=put(i,fnum2c.);
		sort_cid=cid;
		level=nparents[i];
		output;
		do j=1 to dim(p);
			if p[j]=i then do;
				sort_cid=put(j,fnum2c.);
				level=nparents[j];
				output;
				do k=1 to dim(p);
					if p[k]=j then do;
						sort_cid=put(k,fnum2c.);
						level=nparents[k];
						output;
					end;
				end;
			end;
		end;
		level=nparents[i];
		_i=i;
		do while (level&amp;gt;1);
			sort_cid=put(p[_i],fnum2c.);
			level=nparents[p[_i]];
			output;
			_i=p[_i];
		end;
	end;
end;
keep cid sort_cid level;
run;
&lt;BR /&gt;proc sort data=want; by cid sort_cid; run;&lt;BR /&gt;
proc print data=want; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="quickbluefish_0-1732127253825.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102385i0E03774927A81A35/image-size/medium?v=v2&amp;amp;px=400" role="button" title="quickbluefish_0-1732127253825.png" alt="quickbluefish_0-1732127253825.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 18:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951385#M45557</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-11-20T18:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951394#M45558</link>
      <description>&lt;P&gt;So you just need to calculate the depth for each CID and which CID is at the top of their tree.&amp;nbsp; Then you can use BY group processing to create your various counters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
* Load the cid-&amp;gt;parent_cid mapping into a hash ;
  if _n_=1 then do;
    declare hash h(dataset:'have');
    h.definekey('cid');
    h.definedata('parent_cid');
    h.definedone();
  end;
* Load next CID value ;
  set have ;
* Find their top ancestor and how deep they are ;
  do depth=1 by 1 until(h.find());
    top=cid;
    cid=parent_cid;
  end;
* Re-load the same CID value to reset CID and PARENT_CID ;
  set have;
run;

proc sort;
  by top depth cid ;
run;

* find how many levels will be needed ;
proc sql noprint;
  select max(depth) into :md trimmed from want;
quit;

* Use FIRST. processing to get the counters ;
* Concatenate to make index string ;
data numbered;
  set want;
  by top depth cid;
  array c[&amp;amp;md] ;
  c[depth]+1;
  if first.depth then do;
     do j=depth+1 to &amp;amp;md;
       c[j]=1;
     end;
  end;
  drop j ;
  sort_chain=catx('.',of c[*]);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1732134842977.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102386iEF54BCC20ADB18E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1732134842977.png" alt="Tom_0-1732134842977.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;NOTE:&amp;nbsp;&amp;nbsp; If none of the individual counters exceed 9 then you can generate your sort key variable just using CATX() as in this program.&amp;nbsp; But if you do have values like 10 then you might want to code a loop so you can use the Z format to generate strings like 1.10.1 and 1.09.1 instead.&amp;nbsp; Those will sort properly.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 20:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951394#M45558</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-20T20:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951405#M45559</link>
      <description>That's really interesting - I understand the code more or less (I've never set the same dataset twice -seems much less awkward than having to store the original values in separate variables) and understand how you're deriving the sort chain now, but I still don't think I follow what the purpose of it is - like, what is "1.3.1" actually telling us as it relates to CID='d', parent_CID='a'?  Doesn't 'd' have a depth of 2?</description>
      <pubDate>Wed, 20 Nov 2024 23:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951405#M45559</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-11-20T23:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951409#M45560</link>
      <description>&lt;P&gt;That step reads the same dataset three times since it is also loaded into the HASH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we stick to the parent/child analogy we have A as the head of the first family, so 1 for the first place.&amp;nbsp; D is the second child of A, so since A was number 1 for that second position D is number 3.&amp;nbsp; And since the depth of D is two you have 1 for all of the other levels since D is the head that sub-tree.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 23:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951409#M45560</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-20T23:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951410#M45561</link>
      <description>Mind blown... thank you!</description>
      <pubDate>Wed, 20 Nov 2024 23:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951410#M45561</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-11-20T23:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951454#M45562</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again thank you for thinking along!&lt;/P&gt;&lt;P&gt;The resulting dataset looks almost right, however what does not seem correct is obs. 4: this should be 1.2.2, not 1.3.2. Also, the list needs the 'top' column to show 'b', and who are related to 'b' (which are 'a' and 'c').&lt;/P&gt;&lt;P&gt;I will give a full explanation why the format is needed, starting from my final table in Viya, working backwards towards the dataset I have.&lt;/P&gt;&lt;P&gt;My client wants to have an overview of all companies within a certain sector (these are 1000's of companies, so to answer your question: yes, many values will be larger than 10). These companies are related to each other (holding company, daughter companies, branches, etc.). A company can have multiple daughters/branches, but each company only one parent. In the dashboard, these companies need to be shown with their relation to each other in a listtable. Each company is operating in certain sub-sectors. So if the user selects a certain sub-sector, a subset of the companies is returned. BUT, and this is the important part: each company that is returned, must have all the parent/daughter (NOT sister) companies displayed, to understand where in the global sector a company operates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solution to this is to send a table like this to Viya*:&lt;/P&gt;&lt;P&gt;(&lt;EM&gt;note the spaces in front of sort_name, this is derived from the 'level' column in EG, level 1 = no spaces, level 2 = 2 spaces, level 3 = 4 spaces, etc.).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_1-1732178490215.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102399i437F514E3DD50BE0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_1-1732178490215.png" alt="RVO_1-1732178490215.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note that each company (in another table) is linked to sub-sectors via datamapping.&lt;/P&gt;&lt;P&gt;I will use an excel pivot table to mimic the Viya behavior. The following listtable is created in Viya, normally the 'sort chain' column is hidden (now shown for clarity). The result would be:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_3-1732178611121.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102401i60F6E9B7B700AE22/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_3-1732178611121.png" alt="RVO_3-1732178611121.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say the user select subsector 1. And companies 'b' and 'f' are active in that sector. Then the result would be:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_4-1732178822468.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102402i749B6FC1C4BC581F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_4-1732178822468.png" alt="RVO_4-1732178822468.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'e' dropped out, nothing to do with the subsector. But 'a', 'c' and 'g' are shown, because they are related to a company in the chain. Note: in the final version, 'b' and 'f' will be highlighted to show they are the direct result of the filter, while the rest is to show the company structure within the sector (I have that part working if I load the desired output table into Viya when manually created from a small subset of the data).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;whole reason that the above table works, is because:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I have the &lt;STRONG&gt;sort-chain&lt;/STRONG&gt; column.&lt;/LI&gt;&lt;LI&gt;I have the &lt;STRONG&gt;level&lt;/STRONG&gt;-column to create spaces in front of c company name to make the result human-readable.&lt;/LI&gt;&lt;LI&gt;And most important: for&amp;nbsp;&lt;STRONG&gt;each company&lt;/STRONG&gt; in the list&amp;nbsp;&lt;STRONG&gt;all parents and children&lt;/STRONG&gt; are in the table.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To further clarify point 3, while using my original example table in my original post:&lt;/P&gt;&lt;P&gt;Company 'a' is linked to 3 other companies. Hence, for cid 'a', we get sort_cid 'a' (itself), 'b' (first daughter), 'c' (first daughter of first daughter), 'd' (second daughter).&lt;/P&gt;&lt;P&gt;Company 'b'&amp;nbsp; is linked to 2 other companies, being 'a' (its parent), and 'c' (its daughter). So 'b' inherits the first digit from 'a', and digit two gets a +1.&lt;/P&gt;&lt;P&gt;Company 'd' is linked to 1 other company, being 'a' (its parent). So 'd' inherits the first digit from 'a' and digit two gets a +1 (i.e. 3).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also created the below identical working example, but have reduces all sort_chain numbers by 1, maybe that is more logical for some people:&lt;/P&gt;&lt;P&gt;Data sent to Viya:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_5-1732179628978.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102403i75D8A33245793FB6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_5-1732179628978.png" alt="RVO_5-1732179628978.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basic Viya listtable:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_6-1732179635335.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102404i4AB090E90F373BD1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_6-1732179635335.png" alt="RVO_6-1732179635335.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;User selects companies 'b' and 'f'&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_7-1732179641824.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102405iE6931A81D5337359/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_7-1732179641824.png" alt="RVO_7-1732179641824.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 09:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951454#M45562</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-21T09:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951456#M45563</link>
      <description>Hi quickbluefish,&lt;BR /&gt;&lt;BR /&gt;Thank you as well for trying to help me out! Your output table looks (except for the sort_chain) like my output table! I have in another reply tried to better explain the sort_chain (how it works, a different variant that might feel more 'logical', and why it is needed).&lt;BR /&gt;&lt;BR /&gt;My main problem is: I do not understand how your code works (I've only just started to program in SAS EG).&lt;BR /&gt;On a high level I understand that you loop over parent&amp;gt;child (c2num?) and child&amp;gt;parent (num2c?) tables, to get the parents of every child, and the children of every parent. But I do not understand most parts of the code what it does.</description>
      <pubDate>Thu, 21 Nov 2024 09:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951456#M45563</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-21T09:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951467#M45564</link>
      <description>&lt;P&gt;So you just want to add extra observations?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 13:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951467#M45564</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-21T13:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951469#M45565</link>
      <description>Yes, there will be additional observations (1000's of companies). And chains can be long: a company can have many children, grandchildren, grand-grandchildren, etc. (10+ levels deep).</description>
      <pubDate>Thu, 21 Nov 2024 13:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951469#M45565</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-21T13:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951472#M45566</link>
      <description>&lt;P&gt;I do not see how yours is much different than what I produced.&lt;/P&gt;
&lt;P&gt;(Hard to use your photographs since I cannot copy the text from a photograph).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you just want to add the extra observations to replicate the parents that have many children.&amp;nbsp; So instead of just having A 1.1.1 a single time you want it replicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1732196134326.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102407iD77F9FA2D103B8FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1732196134326.png" alt="Tom_0-1732196134326.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 13:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951472#M45566</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-21T13:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951473#M45567</link>
      <description>&lt;P&gt;Converting CID and LEVEL to SORT_NAME is simple using the REPEAT() function.&lt;/P&gt;
&lt;P&gt;Note that the number passed to REPEAT() is the number of EXTRA copies to produce so it always produces at least one copy.&amp;nbsp; If you want the SORT_NAME to look indented like that when printed to ODS destinations then use non-breaking space ('A0'x) instead of a normal space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sort_name=substr(repeat('A0'X,depth)||cid,3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 13:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951473#M45567</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-21T13:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951474#M45568</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439866"&gt;@RVO&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes, there will be additional observations (1000's of companies). And chains can be long: a company can have many children, grandchildren, grand-grandchildren, etc. (10+ levels deep).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So did you try your visualization in VIYA with an example where one of the values between the periods is larger than 9?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1.1.1
1.2.1
1.3.1
...
1.9.1
1.10.1
1.11.1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Did it work as you wanted it?&amp;nbsp; Did it sort properly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 13:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951474#M45568</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-21T13:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951478#M45569</link>
      <description>&lt;P&gt;Correct. Note the&amp;nbsp;&lt;STRONG&gt;sort_chain&lt;/STRONG&gt; is 1-on-1 coupled to&amp;nbsp;&lt;STRONG&gt;sort_name&lt;/STRONG&gt; (each &amp;lt;space&amp;gt;&amp;lt;space&amp;gt;b has sort_chain 1.2.1). This is as mentioned to use it in Viya as required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will show you where ours differ (and that is a very important difference):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_1-1732197738148.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102409i389EA85D5FBAED0C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_1-1732197738148.png" alt="RVO_1-1732197738148.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The two highlighted records should be the same, but mine (correctly) shows 1.2.2, whereas your version shows 1.3.2, which is incorrect, since c is &lt;STRONG&gt;not&lt;/STRONG&gt; a daughter of d (1.3.1).&lt;/P&gt;&lt;P&gt;I understand it is difficult to understand when it is not fully clear why an output is needed. But Viya has many peculiarities compared to coding a user interface where each visual can have SQL code behind it, especially if a company (like the one I work for) tries to misuse Viya for a CRM-system (that is the main problem ;))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 14:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951478#M45569</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-21T14:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951480#M45570</link>
      <description>&lt;P&gt;Hi Tom, in reply to both your questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that the current example breaks when obs &amp;gt; 9. But in my final code (already use it for other parts in my EG script) will use z5. (up to 9999 unique parent companies/daughters/etc.) Can always upgrade to z6., z7, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example where I already use it in another part of my script:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;SPAN&gt; sort_id = cats(sort_id, put(new_id, z3.));&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Example result in Viya for that code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RVO_0-1732198505921.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102410iCD64257D9E6DBF57/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RVO_0-1732198505921.png" alt="RVO_0-1732198505921.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI: Viya does not sort characters after the 5th character (in my testing), so I actually replace the sort_id buy a sort_number in code and use that in Viya:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data &amp;amp;table_out(drop=sort_id);
	set &amp;amp;table_out;
	by sort_id;&lt;BR /&gt;
	if first.sort_id then
		hierarchy_sort_number+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;By using first. all sort_id's that are identical get the same sort_number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding repeat, using this for the example in this reply:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;hierarchy_sort_name = substr(cat(repeat("  ", %eval(&amp;amp;i-1)), hierarchy_level_&amp;amp;i), 3);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The tip to use&amp;nbsp;'A0'x is much appreciated. I currently replace the spaces in Viya in a calculated column with this unicode character:&amp;nbsp;&lt;A href="https://www.compart.com/en/unicode/U+2800" target="_blank" rel="noopener"&gt;https://www.compart.com/en/unicode/U+2800&lt;/A&gt;&amp;nbsp;(braille blank pattern), but I like your suggestion better. When I just tried to copy the unicode charater in EG, it gave me an error and refused to run the script.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The code this is part of actually creates the same effect, but there the hierarchy data is in separate columns (hierarchy_level1, hierarchy_level2, etc). This is just the way the source data is formatted. For some reason that was easy for me to create. But to achieve the same with only parent-child data, recursive coding (CTE?) is required, and I am unfamiliar with it.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 14:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951480#M45570</guid>
      <dc:creator>RVO</dc:creator>
      <dc:date>2024-11-21T14:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Find all parents and children for each record.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951506#M45571</link>
      <description>&lt;P&gt;So that is actually perhaps a little easier.&lt;/P&gt;
&lt;P&gt;To start with build a string with CID values of all of the parents of the current node.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
* Load the cid-&amp;gt;parent_cid mapping into a hash ;
  if _n_=1 then do;
    declare hash h(dataset:'have');
    h.definekey('cid');
    h.definedata('parent_cid');
    h.definedone();
  end;
* Load next CID value ;
  set have ;
  length parents $20;
* Find their parents ;
  do depth=1 by 1 until(h.find(key:parent_cid));
    parents=catx('|',parent_cid,parents);
  end;
  keep cid parents depth ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can generate the numbers you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort;
  by parents cid;
run;

data want;
  set want;
  by parents ;
  order+1;
  if first.parents then order=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then again use a HASH to get the order numbers of the parents of the current node.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data numbered ;
  set want;
  if _n_=1 then do;
    declare hash h(dataset:'want');
    h.definekey('cid');
    h.definedata('order');
    h.definedone();
  end;
  array c[&amp;amp;md];
  c[depth]=order;
  do i=depth+1 to &amp;amp;md;
    c[i]=0;
  end;
  do i=1 to depth-1;
    h.find(key:scan(parents,i,'|'));
    c[i]=order;
  end;
  drop i;
  length sort_name $20 sort_index $30 ;
  sort_name=substr(repeat('A0'x,depth)||cid,3);
  sort_index=catx('.',of c[*]);
run;
proc sort;
  by sort_index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1732200376952.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102431iAE0FB1D318E3AC75/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1732200376952.png" alt="Tom_0-1732200376952.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 14:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Find-all-parents-and-children-for-each-record/m-p/951506#M45571</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-21T14:46:26Z</dc:date>
    </item>
  </channel>
</rss>

