<?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: Cycle detection in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182773#M265308</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i have understood correctly (you are looking for products that are also components) this may be one solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select a.product from have a, have b&lt;/P&gt;&lt;P&gt;where a.product=b.component;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Sep 2014 13:36:06 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2014-09-02T13:36:06Z</dc:date>
    <item>
      <title>Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182772#M265307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am searching a possibility to detect cycles in a data set. For example, it should tell me that Product A has itself as a component in the following data set:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data Have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Input @1 Product $ @3 Component $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Datalines;&lt;/P&gt;&lt;P&gt;M N&lt;/P&gt;&lt;P&gt;N O&lt;/P&gt;&lt;P&gt;A B&lt;/P&gt;&lt;P&gt;B C&lt;/P&gt;&lt;P&gt;C D&lt;/P&gt;&lt;P&gt;D A&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&amp;amp;kind regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 13:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182772#M265307</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-09-02T13:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182773#M265308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i have understood correctly (you are looking for products that are also components) this may be one solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select a.product from have a, have b&lt;/P&gt;&lt;P&gt;where a.product=b.component;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 13:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182773#M265308</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-09-02T13:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182774#M265309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am afraid this only tells me which "products" in the first column are componets of another product.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What the program should do is to check the structure: &lt;SPAN style="text-decoration: underline;"&gt;1.&lt;/SPAN&gt; M consists (in part) of N. N consits of O -&amp;gt; o.k. &lt;SPAN style="text-decoration: underline;"&gt;2.&lt;/SPAN&gt; &lt;STRONG&gt;A&lt;/STRONG&gt; consists of B. B consists of C. C of D. D of &lt;STRONG&gt;A&lt;/STRONG&gt; -&amp;gt; this is a contradiction.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 13:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182774#M265309</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-09-02T13:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182775#M265310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;only one product correspond to one component ?&lt;/P&gt;&lt;P&gt;Or one product can project to multi-component ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182775#M265310</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-02T14:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182776#M265311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, bad example. Multiple Components are possible. This would be a better example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data Have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Input @1 Product $ @3 Component $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Datalines;&lt;/P&gt;&lt;P&gt;M N&lt;/P&gt;&lt;P&gt;N O&lt;/P&gt;&lt;P&gt;A B&lt;/P&gt;&lt;P&gt;B C&lt;/P&gt;&lt;P&gt;B F&lt;/P&gt;&lt;P&gt;B G&lt;/P&gt;&lt;P&gt;C D&lt;/P&gt;&lt;P&gt;D A&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182776#M265311</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-09-02T14:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182777#M265312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have access to SAS/OR, look into the CYCLE statement of PROC OPTNET.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182777#M265312</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-09-02T14:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182778#M265313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I do. will try.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182778#M265313</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-09-02T14:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182779#M265314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Copy Paste of Example 2.2 Cycle Detection for Kidney Donor Exchange worked even for a relatively large data set. Many Thanks !!!!!!!!!!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182779#M265314</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-09-02T14:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182780#M265315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data Have;&lt;BR /&gt;&amp;nbsp; Input @1 Product $ @3 Component $;&lt;BR /&gt;&amp;nbsp; Datalines;&lt;BR /&gt;M N&lt;BR /&gt;N O&lt;BR /&gt;A B&lt;BR /&gt;B C&lt;BR /&gt;B F&lt;BR /&gt;B G&lt;BR /&gt;C D&lt;BR /&gt;D A&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if product&amp;lt;component then flag=0; &lt;BR /&gt;else flag=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;flag=1 will be contradiction.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182780#M265315</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-09-02T14:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Cycle detection in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182781#M265316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like I am late. But just post it here for other user who don't have SAS/OR .&lt;/P&gt;&lt;P&gt;Take a look at LOG to see which one is a circle component.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
data have;
&amp;nbsp;&amp;nbsp;&amp;nbsp; input (_start _end) (:$1.) @@;
&amp;nbsp; cards;
M N
N O
A B
B C
B F
B G
C D
D A
&amp;nbsp; ;
&amp;nbsp; run;


data _null_;
if _n_ eq 1 then do;
length path _path&amp;nbsp; $ 200 ;

if 0 then set have;
*This Hash Table contains the from-to information;
declare hash ha(hashexp:20,dataset:'have',multidata:'Y');
ha.definekey('_start');
ha.definedata('_end');
ha.definedone();

*This Hash Table contains all of branches in a tree,it is very important;
*which we can find all of the from-to ;
declare hash pa(ordered:'Y');
declare hiter hi_path('pa');
pa.definekey('count');
pa.definedata('path');
pa.definedone();

end;

set have;
*initial Hash Table PA, i.e. get the first branch;
count=1;
path=catx(' ',_start,_end);
pa.add();
*Now get start,using Broad Search First&amp;nbsp; to get all of from-to;
do while(hi_path.next()=0);
_path=path;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*_path is for rollback;
_start=scan(path,-1,' '); 
rc=ha.find();
 do while(rc=0);
&amp;nbsp; if not find(path,strip(_end)) then do;
&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; count+1;
&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; path=catx(' ',path,_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;&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; pa.add(); 
&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; path=_path;
&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; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else putlog 'FOUND:' _end 'is a circle component.';
&amp;nbsp; rc=ha.find_next();
 end;
end;
*Now a branch has searched completely,we need to clear it to ;
*prepare for next branch (an observation is a branch);
pa.clear();
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 14:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cycle-detection-in-data-set/m-p/182781#M265316</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-02T14:44:21Z</dc:date>
    </item>
  </channel>
</rss>

