<?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: Create a flow direction in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508208#M136451</link>
    <description>&lt;P&gt;To OP ,Mark, Xia who may have a couple of mins to clarify plz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had this question printed and showed that to a friend of mine who is majoring in data science.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;He&amp;nbsp; pointed out. Isn't it always the following&lt;STRONG&gt; L&lt;/STRONG&gt; shape that's the flow&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;have:&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;from&lt;/TD&gt;
&lt;TD&gt;to&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;a&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;b&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;c&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;d&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;e&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;f&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;f&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;g&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide some intuition?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Oct 2018 01:32:43 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-10-29T01:32:43Z</dc:date>
    <item>
      <title>Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507808#M136323</link>
      <description>&lt;P&gt;Hi, there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just curious how to achieve this in sas. Basically I want to tract each id's full life cycle from the origin to destination as below example shows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;have:&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;from&lt;/TD&gt;&lt;TD&gt;to&lt;/TD&gt;&lt;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gt;&lt;TD&gt;f&lt;/TD&gt;&lt;TD&gt;f&lt;/TD&gt;&lt;TD&gt;g&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;Any comment is highly appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507808#M136323</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-10-26T16:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507811#M136324</link>
      <description>&lt;P&gt;why is f missing if id 2 traveled from e to f and then from f to g?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507811#M136324</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-26T16:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507813#M136325</link>
      <description>&lt;P&gt;Sorry it was a typo. Thanks for pointing out!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507813#M136325</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-10-26T16:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507818#M136327</link>
      <description>&lt;P&gt;Do you have &lt;STRIKE&gt;sas/ets&lt;/STRIKE&gt;&amp;nbsp;(sorry, I meant SAS/OR)?&amp;nbsp;It&amp;nbsp;includes proc optnet, which will directly solve your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run&lt;/P&gt;
&lt;P&gt;&amp;nbsp; proc setinit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and see &lt;STRIKE&gt;if sas/ets&lt;/STRIKE&gt; sas/or is listed.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507818#M136327</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-26T16:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507825#M136328</link>
      <description>&lt;P&gt;It looks like I have sas/or.&lt;BR /&gt;Never use it before, please guide me.&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507825#M136328</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-10-26T16:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507826#M136329</link>
      <description>&lt;P&gt;Yes look for OR as Mark suggested.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But just to clear the air a bit:&lt;/P&gt;
&lt;P&gt;I would have thought the logical result to be&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0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TD&gt;to/from&lt;/TD&gt;
&lt;TD&gt;to/from&lt;/TD&gt;
&lt;TD&gt;to/from&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;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;2&lt;/TD&gt;
&lt;TD&gt;e&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;f&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;f&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;g&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you correct my understanding?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507826#M136329</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-26T16:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507827#M136330</link>
      <description>Yes, your logic is correct, The reason for me to create that two fs is just to align the column such that I can use the last column as the final destination, for future analysis.&lt;BR /&gt;Thanks.</description>
      <pubDate>Fri, 26 Oct 2018 17:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507827#M136330</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-10-26T17:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507831#M136331</link>
      <description>&lt;P&gt;Ok Thanks. Let's together wait if Mark has the time to demo or lead us with some guidance. I am excited about OR too. Thankfully I haven't lost much hair after having learned base sas fairly well. Otherwise your req is a simple double proc transpose&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 17:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507831#M136331</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-26T17:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507975#M136383</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID	from $	to $ ;
rename from=_start to=_end;
cards;
1	a	b
1	b	c
1	c	d
2	e	f
2	f	g
;
run;
 
proc sql;
create table x as
 select * from have
 where catx(' ',id,_start) not in 
(select catx(' ',id,_end) from have);
quit; 

data want(keep=id 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);
   
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;
   
   count+1;n=count;
   path=catx('|',path,_end);
   pa.add();
   path=_path;
 end;
 else output;
  rc=ha.find_next();
end;
end;
pa.clear();

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Oct 2018 11:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/507975#M136383</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-27T11:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508184#M136444</link>
      <description>&lt;P&gt;Having used proc optnet for other from/to linkage tasks, I thought this problem would be convenient to solve.&amp;nbsp; But it's not:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;proc optnet doesn't honor BY groups, so you'd have to run it multiple times, and then concatenate&amp;nbsp;all the by-group results.&lt;/LI&gt;
&lt;LI&gt;Within each ID group you have to ask proc optnet to generate the longest path (a-d is longer than all the others).&amp;nbsp; If would provide 2 such paths for ID group 1:&amp;nbsp; a-&amp;gt;b-&amp;gt;c-&amp;gt;d&amp;nbsp;&amp;nbsp; and d-&amp;gt;c-&amp;gt;b-&amp;gt;a.&amp;nbsp;&amp;nbsp; You'd have to compare the path output file to other output files from optnet to determine which one honors the flow direction desired, and then arrange data to be ready for transpose from tall to wide.&amp;nbsp; A pain you-know-where.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So here's two step solution&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In a data step
&lt;OL&gt;
&lt;LI&gt;make a hash call triple, which
&lt;OL&gt;
&lt;LI&gt;Includes ID as a key in the hash object, making honoring id groups easier&lt;/LI&gt;
&lt;LI&gt;Makes a triple for each node in the path, containing (in addition to ID)&amp;nbsp;&amp;nbsp;&amp;nbsp; NODE, PRIOR, and NEXT&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;At the end of each by group
&lt;OL&gt;
&lt;LI&gt;Find the source (the node with no prior)&lt;/LI&gt;
&lt;LI&gt;output each successive node until reaching the sink (the node with no next)&lt;/LI&gt;
&lt;LI&gt;Label the nodes as "source", "node_2", "node_3", ... to "sink".&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;After the data step run a proc transpose:&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDITTED NOTE:&amp;nbsp;&amp;nbsp; To accommodate a single record ID, a node value has to be arbitrarily assigned prior to the &lt;EM&gt;&lt;STRONG&gt;triple.find()&lt;/STRONG&gt;&lt;/EM&gt; method.&amp;nbsp; That statement ("if missing(node) then node=from;") is included below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input ID from :$1. to :$1.;
datalines;
1 b c 
1 c d 
1 a b 
2 e f 
2 f g 
run;

data need (keep=id nodename node);  
  set have;
  by id;
  if _n_=1 then do;
    length prior node next $1;
	declare hash triples();
	  triples.definekey('id','node');
	  triples.definedata('id','node','prior','next');
	  triples.definedone();
  end;

  /*Populate triples hash */
  if triples.find(key:id,key:from)^=0 then call missing(prior);
  triples.replace(key:id,key:from,data:id,data:from,data:prior,data:to);

  if triples.find(key:id,key:to)^=0 then call missing(next);
  triples.replace(key:id,key:to,data:id,data:to,data:from,data:next);

  if last.id;
  triples.output(dataset:'triples');

  if missing(node) then node=from;  /*Added to accommodate single-link ID's*/
  triples.find();
  if not missing(prior) then do until (missing(prior));
    triples.find(key:id,key:prior);
  end;

  nodename='Source'; /* Output nodes from source to sink */
  output;
  if not missing(next) then do seq=2 by 1 until(missing(next));
    triples.find(key:id,key:next);
	if missing(next) then nodename='Sink';
    else nodename=cats('Node_',seq);
    output; 
  end;
run;

proc transpose data=need out=want (drop=_name_) ;
  by id;
  var node;
  id nodename;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only part of the original request unsatisfied here is that some internal values (such as NODE_3 for id group 2) are missing.&amp;nbsp; That should be easy to fix, if really necessary.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 04:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508184#M136444</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-29T04:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508208#M136451</link>
      <description>&lt;P&gt;To OP ,Mark, Xia who may have a couple of mins to clarify plz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had this question printed and showed that to a friend of mine who is majoring in data science.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;He&amp;nbsp; pointed out. Isn't it always the following&lt;STRONG&gt; L&lt;/STRONG&gt; shape that's the flow&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;have:&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;from&lt;/TD&gt;
&lt;TD&gt;to&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;a&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;b&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;c&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;d&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;e&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;f&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;f&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;g&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide some intuition?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 01:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508208#M136451</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-29T01:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508230#M136465</link>
      <description>&lt;P&gt;I wrote my program to accommodate any sequence of links within an ID group.&amp;nbsp; Although the example had each link descend from the prior record, the OP didn't state that as a condition.&amp;nbsp; But if that condition can be guaranteed to always be the case then the program is much simpler.&amp;nbsp;&amp;nbsp; Just copy&amp;nbsp;the sequence of FROM values and append the final TO value for each ID.&amp;nbsp; Then transpose:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id  from :$1. to :$1.;
datalines;
1 a b 
1 b c 
1 c d 
2 e f 
2 f g 
run;

data vneed / view=vneed;
  set have;
  by id;
  seq+1;
  if first.id then seq=1;
  if first.id then nodename='Source';
  else nodename=cats('Node_',seq);
  output;
  if last.id ;
  from=to;
  nodename='Sink';
  output;
run;

proc transpose data=vneed out=want (drop=_name_);
  by id;
  var from;
  id nodename;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Oct 2018 04:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508230#M136465</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-29T04:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508231#M136466</link>
      <description>&lt;P&gt;Thanks a lot for the explanation. Hash is absolutely new to me and just test the code but give an error when I am adding new case: there only contains source and sink node as id3? Would you please show me how can i modify the code accordingly? Thanks!!!&lt;/P&gt;&lt;PRE&gt;data have ;
  input ID from :$1. to :$1.;
datalines;
1 b c 
1 c d 
1 a b 
2 e f 
2 f g 
3 x y
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 04:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508231#M136466</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-10-29T04:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508232#M136467</link>
      <description>&lt;P&gt;Thanks a lot! I tested the code, it gives me same id with various different path. I will need to closely investigate my data source.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 04:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508232#M136467</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-10-29T04:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508233#M136468</link>
      <description>&lt;P&gt;Please show the log containing the error message and related source code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 04:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508233#M136468</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-29T04:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508236#M136469</link>
      <description>&lt;PRE&gt;data have ;
  input ID from :$1. to :$1.;
datalines;
1 b c 
1 c d 
1 a b 
2 e f 
2 f g 
3 x y
run;

data need (keep=id nodename node);  
  set have;
  by id;
  if _n_=1 then do;
    length prior node next $1;
	declare hash triples();
	  triples.definekey('id','node');
	  triples.definedata('id','node','prior','next');
	  triples.definedone();
  end;

  /*Populate triples hash */
  if triples.find(key:id,key:from)^=0 then call missing(prior);
  triples.replace(key:id,key:from,data:id,data:from,data:prior,data:to);

  if triples.find(key:id,key:to)^=0 then call missing(next);
  triples.replace(key:id,key:to,data:id,data:to,data:from,data:next);

  if last.id;
  triples.output(dataset:'triples');

  triples.find();
  if not missing(prior) then do until (missing(prior));
    triples.find(key:id,key:prior);
  end;

  nodename='Source'; /* Output nodes from source to sink */
  output;
  if not missing(next) then do seq=2 by 1 until(missing(next));
    triples.find(key:id,key:next);
	if missing(next) then nodename='Sink';
    else nodename=cats('Node_',seq);
    output; 
  end;
run;

proc transpose data=need out=want (drop=_name_) ;
  by id;
  var node;
  id nodename;
run;&lt;/PRE&gt;&lt;P&gt;basically I create a new case with id3, there is only two nodes x and y. The error in the log file shows:&lt;/P&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;55&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;56 data have ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;57 input ID from :$1. to :$1.;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;58 datalines;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.HAVE has 6 observations and 3 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;65 run;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;66&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;67 data need (keep=id nodename node);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;68 set have;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;69 by id;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;70 if _n_=1 then do;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;71 length prior node next $1;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;72 declare hash triples();&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;73 triples.definekey('id','node');&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 triples.definedata('id','node','prior','next');&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;75 triples.definedone();&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;76 end;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;77&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;78 /*Populate triples hash */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;79 if triples.find(key:id,key:from)^=0 then call missing(prior);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;80 triples.replace(key:id,key:from,data:id,data:from,data:prior,data:to);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;81&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;82 if triples.find(key:id,key:to)^=0 then call missing(next);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;83 triples.replace(key:id,key:to,data:id,data:to,data:from,data:next);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;84&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;85 if last.id;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;86 triples.output(dataset:'triples');&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;87&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;88 triples.find();&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;89 if not missing(prior) then do until (missing(prior));&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;90 triples.find(key:id,key:prior);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;91 end;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;92&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;93 nodename='Source'; /* Output nodes from source to sink */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;94 output;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;95 if not missing(next) then do seq=2 by 1 until(missing(next));&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;96 triples.find(key:id,key:next);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;97 if missing(next) then nodename='Sink';&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;98 else nodename=cats('Node_',seq);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;99 output;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;100 end;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;101 run;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable node is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.TRIPLES has 4 observations and 4 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.TRIPLES has 7 observations and 4 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.TRIPLES has 9 observations and 4 variables.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Key not found.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 6 observations read from the data set WORK.HAVE.&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: The data set WORK.NEED may be incomplete. When this step was stopped there were 8 observations and 3 variables.&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Data set WORK.NEED was not replaced because this step was stopped.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;real time 0.04 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;cpu time 0.02 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;102&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;103 proc transpose data=need out=want (drop=_name_) ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;104 by id;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;105 var node;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;106 id nodename;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;107 run;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 8 observations read from the data set WORK.NEED.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.WANT has 3 observations and 5 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: PROCEDURE TRANSPOSE used (Total process time):&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;real time 0.01 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;108&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;109&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;110 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;122&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;Thanks!!!&lt;/DIV&gt;</description>
      <pubDate>Mon, 29 Oct 2018 04:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508236#M136469</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-10-29T04:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create a flow direction in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508314#M136514</link>
      <description>&lt;PRE&gt;
No. It can be settled randomly.
Or have a dead loop like:


ID	from	to
1	a	b
1	b	c
1	c	d
1      d      a


&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Oct 2018 12:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-flow-direction-in-proc-sql/m-p/508314#M136514</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-29T12:22:50Z</dc:date>
    </item>
  </channel>
</rss>

