<?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: Hierachy data (Parent Child) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490789#M128518</link>
    <description>&lt;P&gt;You could split this table into two tables and running my code separately .&lt;/P&gt;
&lt;P&gt;If you have many a, make a macro to go through all of a . That is not too difficulty .&lt;/P&gt;</description>
    <pubDate>Wed, 29 Aug 2018 11:45:43 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-08-29T11:45:43Z</dc:date>
    <item>
      <title>Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490205#M128185</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt; a=1; b=5.1; c=5.5; output;&lt;BR /&gt; a=1; b=5.2; c=5.5; output;&lt;BR /&gt; a=1; b=5.0; c=5.2; output;&lt;/P&gt;
&lt;P&gt;a=1; b=4.7; c=5.0; output;&lt;BR /&gt; a=1; b=4.6; c=5.2; output;&lt;/P&gt;
&lt;P&gt;a=1; b=.; c=4.6; output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a output in which for a given parent nodie (variable c) it should get all the childs/nodes (variable b) which should not have any child/nodes. for e.g in the above example for parent node&amp;nbsp;with value 5.5 it should output 5.1, 4.7 and 4.6 which do not have any child.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how the output is picked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;5.5 has 5.1 and 5.2 child, then 5.2 has child 5.0, 5.0 has child 4.7 and 5.2 has child 4.6.&amp;nbsp; 4.6, 4.7 and 5.1 do not have any childs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if you need more expalnation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for the help.&lt;/P&gt;
&lt;P&gt;Anand&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>Mon, 27 Aug 2018 17:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490205#M128185</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2018-08-27T17:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490212#M128187</link>
      <description>&lt;P&gt;Are we to understand that a child node has a number &amp;lt; parent node number? Why not code the child node number as missing when it is greater than the parent node?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 18:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490212#M128187</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-08-27T18:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490216#M128188</link>
      <description>&lt;P&gt;Is your desired result a data set? Can you show us what your desired result looks like?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 18:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490216#M128188</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-08-27T18:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490229#M128199</link>
      <description>&lt;P&gt;I this case the output will be&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;new variable&lt;/P&gt;
&lt;P&gt;5.1&lt;/P&gt;
&lt;P&gt;4.7&lt;/P&gt;
&lt;P&gt;4.6&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All this do not have any child nodes or children for the ancestor or parent 5.5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically when user asks variable c with value 5.5 then output should be look like above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steps are&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. The program reads c variable where value is 5.5 and then looks for the children which is variable b and the values are 5.1 and 5.2&lt;/P&gt;
&lt;P&gt;2. For each of b value which is 5.1 and 5.2 the program looks for children and their children are for 5.1 no children so it will appear in the report and 5.2 has children 5.0... and it goes on for all the childrens...&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 12:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490229#M128199</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2018-08-28T12:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490505#M128335</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(keep=_start _end);
a=1; b='5.1'; c='5.5'; output;
a=1; b='5.2'; c='5.5'; output;
a=1; b='5.0'; c='5.2'; output;

a=1; b='4.7'; c='5.0'; output;
a=1; b='4.6'; c='5.2'; output;

a=1; b=' '; c='4.6'; output;
rename c=_start b=_end;
run;
proc sql;
create table _have as
 select *
  from have where _start not in (select _end from have);
quit;


data want(keep=path want);
if _n_ eq 1 then do;
length path _path  $ 800 ;
if 0 then set have;
declare hash ha(hashexp:20,dataset:'have(where=(_start is not missing and _end is not missing))',multidata:'y');
ha.definekey('_start');
ha.definedata('_end');
ha.definedone();

declare hash pa(ordered:'y');
declare hiter hi_path('pa');
pa.definekey('n');
pa.definedata('n','path');
pa.definedone();

end;


set _have;
count=1;n=1;_n=1;
path=catx('|',_start,_end);
   
pa.add();
do while(hi_path.next()=0);
 if n ne 1 then pa.remove(key:_n);_n=n;
 _path=path;   
 _start=scan(path,-1,'|');
 rc=ha.find();
 if rc ne 0 then do; want=_start;output;end;
 do while(rc=0);
  if not findw(path,strip(_end),'|') then do;
   if length(path)+length(_end)+1 gt lengthc(path) then do;
    putlog 'ERROR: The length of path and _path are set too short';
    stop;
   end;
   
   count+1;n=count;
   path=catx('|',path,_end);
   pa.add(); 
   path=_path;
 end;
  rc=ha.find_next();
end;
end;
pa.clear();

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Aug 2018 15:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490505#M128335</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-28T15:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490521#M128343</link>
      <description>&lt;P&gt;Thank you very much. Its kind of working. But I need to output this based on value a and c. In this case the variable value for a is 1 and c is 5.5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;a=1; b=5.1; c=5.5; output;&lt;BR /&gt;a=1; b=5.2; c=5.5; output;&lt;BR /&gt;a=1; b=5.0; c=5.2; output;&lt;BR /&gt;a=1; b=4.7; c=5.0; output;&lt;BR /&gt;a=1; b=4.6; c=5.2; output;&lt;BR /&gt;a=1; b=.; c=4.6; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;a=2; b=5.4; c=6.1; output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a=2; b=5.3; c=6.1; output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a=2; b=5.0; c=5.3; output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a=2; b=4.7; c=5.0; output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a=2; b=4.5; c=4.7; output;&lt;/SPAN&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the second set of record where a=2 and lets say value c is 6.1 the children output must be as below&lt;/P&gt;
&lt;P&gt;5.4&lt;/P&gt;
&lt;P&gt;4.5&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only these two do not have children.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am sorry for not mentioning this case earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 15:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490521#M128343</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2018-08-28T15:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490787#M128516</link>
      <description>&lt;P&gt;You could split this table into two tables and running my code separately .&lt;/P&gt;
&lt;P&gt;If you have many a, make a macro to go through all of a . That is not too difficulty .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 11:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490787#M128516</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-29T11:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490789#M128518</link>
      <description>&lt;P&gt;You could split this table into two tables and running my code separately .&lt;/P&gt;
&lt;P&gt;If you have many a, make a macro to go through all of a . That is not too difficulty .&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 11:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/490789#M128518</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-29T11:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/491268#M128788</link>
      <description>&lt;P&gt;OK. Since I have some time. Check the following code .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
a=1; b=5.1; c=5.5; output;
a=1; b=5.2; c=5.5; output;
a=1; b=5.0; c=5.2; output;
a=1; b=4.7; c=5.0; output;
a=1; b=4.6; c=5.2; output;
a=1; b=.; c=4.6; output;

 

a=2; b=5.4; c=6.1; output;
a=2; b=5.3; c=6.1; output;
a=2; b=5.0; c=5.3; output;
a=2; b=4.7; c=5.0; output;
a=2; b=4.5; c=4.7; output;

rename c=_start b=_end;
run;



proc sql;
create table _have as
 select distinct a,_start
  from have where catx(' ',a,_start) not in (select catx(' ',a,_end) from have);
quit;


data want(keep=a _start  want);
if _n_ eq 1 then do;
if 0 then set have;
length key n path 8;
declare hash ha(hashexp:20,dataset:'have(where=(_start is not missing and _end is not missing))',multidata:'y');
ha.definekey('a','_start');
ha.definedata('_end');
ha.definedone();

declare hash pa(ordered:'y');
declare hiter hi_path('pa');
pa.definekey('n');
pa.definedata('n','path');
pa.definedone();

declare hash k();
k.definekey('key');
k.definedone();
end;


set _have;
count=1;n=1;_n=1;
path=_start;pa.add();
key=_start;k.add();
do while(hi_path.next()=0);
 if n ne 1 then pa.remove(key:_n);_n=n;
 rc=ha.find(key:a,key:path);
 if rc ne 0 then do; want=path;output;end;
 do while(rc=0);
  if k.check(key:_end) ne 0 then do;
   count+1;n=count;
   path=_end;
   pa.add();   
   key=_end;
   k.add();
 end;
  rc=ha.find_next();
end;
end;
pa.clear();	k.clear();

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Aug 2018 14:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/491268#M128788</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-30T14:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/491390#M128850</link>
      <description>&lt;P&gt;Thank you.. I am able to solve this issue with another approach. Thanks for all your help&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 19:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/491390#M128850</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2018-08-30T19:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579224#M164399</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me in solving problem below. I am providing here the appropriate ancestor for each of the record. &amp;nbsp;I need to find this ancestor for each of the record by &lt;STRONG&gt;user&lt;/STRONG&gt;. Can you please help.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;1&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.1&lt;/STRONG&gt;; cur=&lt;STRONG&gt;4.2&lt;/STRONG&gt;; output; /* 4.1 to 4.2 - Ancestor here is 4.4 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;1&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.2&lt;/STRONG&gt;; cur=&lt;STRONG&gt;4.4&lt;/STRONG&gt;; output; /* 4.2 to 4.4 - Ancestor here is 4.4 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;1&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.6&lt;/STRONG&gt;; cur=&lt;STRONG&gt;5.5&lt;/STRONG&gt;; output; /* 4.6 to 5.5 - Ancestor here is 6.1 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;1&lt;/STRONG&gt;; base=&lt;STRONG&gt;5.5&lt;/STRONG&gt;; cur=&lt;STRONG&gt;6.1&lt;/STRONG&gt;; output; /* 5.5 to 6.1 - Ancestor here is 6.1 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;2&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.2&lt;/STRONG&gt;; cur=&lt;STRONG&gt;4.6&lt;/STRONG&gt;; output; /* 4.2 to 4.6 - Ancestor here is 6.1 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;2&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.6&lt;/STRONG&gt;; cur=&lt;STRONG&gt;5.5&lt;/STRONG&gt;; output; /* 4.6 to 5.5 - Ancestor here is 6.1 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;2&lt;/STRONG&gt;; base=&lt;STRONG&gt;5.5&lt;/STRONG&gt;; cur=&lt;STRONG&gt;6.1&lt;/STRONG&gt;; output;&amp;nbsp; /* 5.0 to 6.1 - Ancestor here is 6.1 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;3&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.0&lt;/STRONG&gt;; cur=&lt;STRONG&gt;4.2&lt;/STRONG&gt;; output; /* 4.0 to 4.2 - Ancestor here is 5.5 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;3&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.2&lt;/STRONG&gt;; cur=&lt;STRONG&gt;4.6&lt;/STRONG&gt;; output; /* 4.2 to 4.6 - Ancestor here is 5.5 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user=&lt;STRONG&gt;3&lt;/STRONG&gt;; base=&lt;STRONG&gt;4.6&lt;/STRONG&gt;; cur=&lt;STRONG&gt;5.5&lt;/STRONG&gt;; output; /* 4.6 to 6.1 - Ancestor here is 5.5 */&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am able to achieve this if there is only one user in the dataset using code below. But its not working if there are more than one user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; _tmp1(rename=(base=base1 cur=cur1));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set a;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;**Repeat the training module for each of the delta version between base and current module;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; _tmp2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain base cur;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set _tmp1; by u;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur = cur1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; base = base1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop base1 cur1 i;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;**Get all the base version for the current modue which has training then need to check the&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; corresponding base version full access;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; _lineage;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set _tmp2;&amp;nbsp; by u; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array hist(&lt;STRONG&gt;6&lt;/STRONG&gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count=&lt;STRONG&gt;1&lt;/STRONG&gt;;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hist(count)=base;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=&lt;STRONG&gt;1&lt;/STRONG&gt; to last while (count&amp;lt;dim(hist)-&lt;STRONG&gt;1&lt;/STRONG&gt;);&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;&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;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set _tmp2(rename=(base=base1 cur=cur1)) nobs=last point=i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cur=base1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; count+&lt;STRONG&gt;1&lt;/STRONG&gt;;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;hist(count)=base1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; base=base1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; cur=cur1;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;i=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hist(count)=cur;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ancest = cur;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&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;</description>
      <pubDate>Mon, 05 Aug 2019 20:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579224#M164399</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2019-08-05T20:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579381#M164460</link>
      <description>You can split the table into three tables and run your code separately ?

data user1;
 set a;
if user=1;
run;

...........</description>
      <pubDate>Tue, 06 Aug 2019 14:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579381#M164460</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-08-06T14:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579422#M164480</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;I have lot of records in the dataset not just 3. It will take lot of time to process if i write a macro to subset these. Is there a way i can do it in one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 15:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579422#M164480</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2019-08-06T15:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579442#M164482</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16856"&gt;@anandbillava&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;I have lot of records in the dataset not just 3. It will take lot of time to process if i write a macro to subset these. Is there a way i can do it in one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Creating subsets won't decrease the time required to create the final result. Do you get any errors while processing the complete dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 16:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579442#M164482</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-08-06T16:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579451#M164483</link>
      <description>&lt;P&gt;I will have to create more than 4000 datasets which is am already doing and its taking lot of time to process.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 17:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579451#M164483</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2019-08-06T17:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Hierachy data (Parent Child)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579504#M164494</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16856"&gt;@anandbillava&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a different approach where splitting the input data set is avoided. I think it gives the wanted output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Orphans are identified by a&amp;nbsp; SQL join, where the input data set is joined by itself with match on user as as a join criteria, so it holds childs and parents with the same user together.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ancestors are handled by a format to set parents on childs, and this it done in a loop, until the chain is exhausted. It makes use of extra variables, where user-base, resp user-cur, are concatenated, so user becomes part of the key.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* test data 1 */
data have1;
	format user 8. cur base 10.1;
	user=0; base=5.1; cur=5.5; output;
	user=0; base=5.2; cur=5.5; output;
	user=0; base=5.0; cur=5.2; output;
	user=0; base=4.7; cur=5.0; output;
	user=0; base=4.6; cur=5.2; output;
	user=0; base=.; cur=4.6; output;
	user=2; base=5.4; cur=6.1; output;
	user=2; base=5.3; cur=6.1; output;
	user=2; base=5.0; cur=5.3; output;
	user=2; base=4.7; cur=5.0; output;
	user=2; base=4.5; cur=4.7; output;
run;

/* find orphans */
proc sql;
	create table orphans as 
		select a.user, coalesce(a.base,a.cur) as orphan format=3.1 
		from have1 as a left join have1 as b
		on a.user = b.user and (b.cur = a.base or b.cur = .)
		where b.user = .;
quit;

/* test data 2 */
data have2;
	format user 8. cur base 10.1;
	user=1; base=4.1; cur=4.2; output; /* 4.1 to 4.2 - Ancestor here is 4.4 */
	user=1; base=4.2; cur=4.4; output; /* 4.2 to 4.4 - Ancestor here is 4.4 */
	user=1; base=4.6; cur=5.5; output; /* 4.6 to 5.5 - Ancestor here is 6.1 */
	user=1; base=5.5; cur=6.1; output; /* 5.5 to 6.1 - Ancestor here is 6.1 */
	user=2; base=4.2; cur=4.6; output; /* 4.2 to 4.6 - Ancestor here is 6.1 */
	user=2; base=4.6; cur=5.5; output; /* 4.6 to 5.5 - Ancestor here is 6.1 */
	user=2; base=5.5; cur=6.1; output; /* 5.0 to 6.1 - Ancestor here is 6.1 */
	user=3; base=4.0; cur=4.2; output; /* 4.0 to 4.2 - Ancestor here is 5.5 */
	user=3; base=4.2; cur=4.6; output; /* 4.2 to 4.6 - Ancestor here is 5.5 */
	user=3; base=4.6; cur=5.5; output; /* 4.6 to 6.1 - Ancestor here is 5.5 */
run;
		
/* Find ancestors */
data w; set have2 end=eof;
	type = 'C'; hlo=''; fmtname = 'par';
	start = put(user,z8.)||'-'||put(base,z10.1);
	label = put(user,z8.)||'-'||put(cur,z10.1);
	output;
	if eof then do;
		hlo = 'O'; label='';
		output;
	end;
run;
proc format cntlin=w;
run;
data ancestors; 
	drop type hlo fmtname start label c w inter;
	set w (where=(hlo=''));
	format ancestor 10.1;
	c = 0;
	do until (w = .);
		c = c + 1;
		if c = 1 then inter = put(start,$par.); else inter = put(inter,$par.);
		w = input(scan(inter,2,'-'),10.1);
		if w ne . then ancestor = w;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 21:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hierachy-data-Parent-Child/m-p/579504#M164494</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-08-06T21:10:55Z</dc:date>
    </item>
  </channel>
</rss>

