BookmarkSubscribeRSS Feed
mkeintz
PROC Star

I wrote my program to accommodate any sequence of links within an ID group.  Although the example had each link descend from the prior record, the OP didn't state that as a condition.  But if that condition can be guaranteed to always be the case then the program is much simpler.   Just copy the sequence of FROM values and append the final TO value for each ID.  Then transpose:

 

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Ksharp
Super User
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


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 16 replies
  • 1709 views
  • 4 likes
  • 4 in conversation