<?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: Colum ordenation to make a sequence - Enterprise Guide in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563686#M10923</link>
    <description>Hi Tom!&lt;BR /&gt;&lt;BR /&gt;I'm not trying to traverse any graph.&lt;BR /&gt;The data is a trail, looks like a production sequence. To make a car, I've to do many steps and after all steps I've the production sequence.&lt;BR /&gt;&lt;BR /&gt;Did you understood my explanation? Is it clear?</description>
    <pubDate>Wed, 05 Jun 2019 12:30:35 GMT</pubDate>
    <dc:creator>Ovaty</dc:creator>
    <dc:date>2019-06-05T12:30:35Z</dc:date>
    <item>
      <title>Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563604#M10907</link>
      <description>&lt;P&gt;Hi everybody!&lt;/P&gt;&lt;P&gt;Good afternoon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today I've a issue to solve in my job. I've a database that have 2 columns to ordinate them into a sequence.&lt;/P&gt;&lt;P&gt;The colum t0 (is the origin) and t1 (is the receptor).&lt;/P&gt;&lt;P&gt;I need to do a program to make a sequence linked t0 to t1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's show you my example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;t0&lt;/TD&gt;&lt;TD&gt;t1&lt;/TD&gt;&lt;/TR&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;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;seq2&lt;/TD&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;I&lt;/TD&gt;&lt;TD&gt;J&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;seq3&lt;/TD&gt;&lt;TD&gt;O&lt;/TD&gt;&lt;TD&gt;P&lt;/TD&gt;&lt;TD&gt;Q&lt;/TD&gt;&lt;TD&gt;R&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thaks a lot to everyone!!&lt;/P&gt;&lt;P&gt;Gustavo.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 20:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563604#M10907</guid>
      <dc:creator>Ovaty</dc:creator>
      <dc:date>2019-06-04T20:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563606#M10908</link>
      <description>&lt;P&gt;Looks like you are trying to traverse a graph.&amp;nbsp; Your output looks backwards.&amp;nbsp; You are moving from T1 to T0 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible that your input data has any cycles?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 20:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563606#M10908</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-04T20:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563686#M10923</link>
      <description>Hi Tom!&lt;BR /&gt;&lt;BR /&gt;I'm not trying to traverse any graph.&lt;BR /&gt;The data is a trail, looks like a production sequence. To make a car, I've to do many steps and after all steps I've the production sequence.&lt;BR /&gt;&lt;BR /&gt;Did you understood my explanation? Is it clear?</description>
      <pubDate>Wed, 05 Jun 2019 12:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563686#M10923</guid>
      <dc:creator>Ovaty</dc:creator>
      <dc:date>2019-06-05T12:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563700#M10924</link>
      <description>&lt;P&gt;The type of data you have is called a graph.&amp;nbsp; They are used in computer science and other fields.&lt;/P&gt;
&lt;P&gt;The nodes of the graph are the values of your two variables (A, B, etc) and each observations represents an edge in the graph (the line between the nodes).&amp;nbsp; You appear to have directed lines that go from the node in T1 to the node in T0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many examples of code on this site for finding connected components (or subgraphs).&lt;/P&gt;
&lt;P&gt;If you have SAS/OR licensed there are procs that can help you.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 13:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563700#M10924</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-05T13:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563714#M10926</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have(keep=t0 t1 rename=(t0=_end t1=_start));
infile cards expandtabs;
input x $ y	t0 $ t1 $;
cards;
Line 1	H	G
Line 2	B	A
Line 3	P	O
Line 4	C	B
Line 5	Q	P
Line 6	I	H
Line 7	D	C
Line 8	R	Q
Line 9	J	I
;
run;
proc sql;
create table x as
select distinct _start,_end
 from have
  where _start not in (select distinct _end from have);
quit;



 

data want(keep=path);
if _n_ eq 1 then do;
length path _path  $ 700 ;
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 x;
count=1;n=1;_n=1;
path=catx('|',_start,_end);
*putlog 'WARNING:Found  ' _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;
 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;
   
   *putlog 'WARNING:Found  ' _end;
   count+1;n=count;
   path=catx('|',path,_end);
   pa.add(); 
   path=_path;
 end; &lt;BR /&gt; else output; /* &amp;lt;--Changed. It is a circle.*/
  rc=ha.find_next();
end;
end;
pa.clear();

run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jun 2019 12:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563714#M10926</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-06T12:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563742#M10929</link>
      <description>Great Ksharp! Tks a lot.&lt;BR /&gt;&lt;BR /&gt;One last question...&lt;BR /&gt;How can I put each values like A|B|C|D in each column?&lt;BR /&gt;&lt;BR /&gt;Gustavo.</description>
      <pubDate>Wed, 05 Jun 2019 16:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563742#M10929</guid>
      <dc:creator>Ovaty</dc:creator>
      <dc:date>2019-06-05T16:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563837#M10941</link>
      <description>&lt;P&gt;Hi Ksharp, I've send a example file.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 19:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/563837#M10941</guid>
      <dc:creator>Ovaty</dc:creator>
      <dc:date>2019-06-05T19:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Colum ordenation to make a sequence - Enterprise Guide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/564078#M10982</link>
      <description>&lt;P&gt;OK. Here is . I change the code a little bit just for case of LOOP ,if you have it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='c:\temp\test_base.txt' out=have(rename=(start=_start end=_end)) replace dbms=tab;
run;


proc sql;
create table x as
select distinct _start,_end
 from have
  where _start not in (select distinct _end from have);
quit;



 

data want(keep=path);
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 x;
count=1;n=1;_n=1;
path=catx('|',_start,_end);
*putlog 'WARNING:Found  ' _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;
 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;
   
   *putlog 'WARNING:Found  ' _end;
   count+1;n=count;
   path=catx('|',path,_end);
   pa.add(); 
   path=_path;
 end;  else output; /* &amp;lt;--Changed. It is a circle.*/
  rc=ha.find_next();
end;
end;
pa.clear();

run;

proc sql noprint;
select max(countw(path,'|')) into : n separated by ' '
 from want;
quit;

data final_want;
 set want;
 array col{*} $ 100 col1-col&amp;amp;n;
 do i=1 to countw(path,'|');
  col{i}=scan(path,i,'|');
 end;
 drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jun 2019 13:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Colum-ordenation-to-make-a-sequence-Enterprise-Guide/m-p/564078#M10982</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-06T13:14:16Z</dc:date>
    </item>
  </channel>
</rss>

