<?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: Trace all the paths from source id in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545190#M16779</link>
    <description>&lt;P&gt;Here is. Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input _start $ _end $;
cards;
1 2
2 3
2 5
3 6
4 8
8 9
9 4
;
run;
 

data want(keep=path);
if _n_ eq 1 then do;
length path _path  $ 400 ;
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 output; /*It is the longest path*/
 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;
  else output; /*It is a circle*/
  rc=ha.find_next();
end;
end;
pa.clear();
run;


proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Mar 2019 11:50:02 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-03-22T11:50:02Z</dc:date>
    <item>
      <title>Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545003#M16768</link>
      <description>I have a dataset which contains pid, cid. I want to get the list of all the possible paths of each pid.&lt;BR /&gt;Example data as below&lt;BR /&gt;Pid cid&lt;BR /&gt;1 2&lt;BR /&gt;2 3&lt;BR /&gt;2 5&lt;BR /&gt;3 6&lt;BR /&gt;4 8&lt;BR /&gt;8 9&lt;BR /&gt;9 4&lt;BR /&gt;My expected result is&lt;BR /&gt;1 2 3 6&lt;BR /&gt;1 2 5&lt;BR /&gt;2 3 6&lt;BR /&gt;2 5&lt;BR /&gt;3 6&lt;BR /&gt;4 8 9 .&lt;BR /&gt;8 9&lt;BR /&gt;9 4&lt;BR /&gt;If the path is about to loop then i want to blank out the value and stop it to avoid any infinite loopings.</description>
      <pubDate>Thu, 21 Mar 2019 19:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545003#M16768</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2019-03-21T19:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545008#M16769</link>
      <description>My expected result is&lt;BR /&gt;1 2 3 6&lt;BR /&gt;1 2 5&lt;BR /&gt;2 3 6&lt;BR /&gt;2 5&lt;BR /&gt;3 6&lt;BR /&gt;4 8 9 .&lt;BR /&gt;8 9 4&lt;BR /&gt;9 4&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Mar 2019 20:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545008#M16769</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2019-03-21T20:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545011#M16770</link>
      <description>&lt;P&gt;The option I'm aware of is PROC OPTNET, which takes the heavy lifting out of the recursion. I'll be interested to see what other options people post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 20:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545011#M16770</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-03-21T20:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545108#M16773</link>
      <description>Thanks Tom!&lt;BR /&gt;But i don't have the SAS/OR. Hence this proc optnet is not available for&lt;BR /&gt;me. Would like to do this with other logics&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Mar 2019 00:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545108#M16773</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2019-03-22T00:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545127#M16774</link>
      <description>&lt;P&gt;I would trust &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; to come up with an excellent hash-based solution for this. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 03:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545127#M16774</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-22T03:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545190#M16779</link>
      <description>&lt;P&gt;Here is. Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input _start $ _end $;
cards;
1 2
2 3
2 5
3 6
4 8
8 9
9 4
;
run;
 

data want(keep=path);
if _n_ eq 1 then do;
length path _path  $ 400 ;
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 output; /*It is the longest path*/
 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;
  else output; /*It is a circle*/
  rc=ha.find_next();
end;
end;
pa.clear();
run;


proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 11:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545190#M16779</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-22T11:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545250#M16782</link>
      <description>Awesome!!! Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&lt;BR /&gt;Works like a charm.. Still am learning your code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545250#M16782</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2019-03-22T15:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545384#M16784</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;,&amp;nbsp;very cool! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 21:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545384#M16784</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-22T21:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Trace all the paths from source id</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545414#M16785</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; awesome job.. Thanks.. It works cool &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sat, 23 Mar 2019 03:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Trace-all-the-paths-from-source-id/m-p/545414#M16785</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2019-03-23T03:03:39Z</dc:date>
    </item>
  </channel>
</rss>

