BookmarkSubscribeRSS Feed
sleretrano
Quartz | Level 8

I'm using SAS EG 5.1 on Windows 7.

 

I have the following sample input.

Input.jpg

 

I wish to order this input in such a way that whenever different observations match on ID and on Time, the final state of a given observation matches the initial state of the next observation.

 

The output should look like this:

Output.jpg

 

I'm at a loss on how to do this. Any help?

 

Here's the code that generates the input table.

Data Test;
   Infile datalines delimiter=','; 
   Input ID Initial_Stafe $ Final_State $ Time;
   Datalines;
   123,AA,BB,201701020923
   123,BB,CC,201701020930
   156,AA,AA,201701020910
   163,AC,BC,201701031010
   163,DD,CC,201701031010
   163,BC,DD,201701031010
   163,CC,BB,201701031010
   170,BB,.,201701040930
;

 

3 REPLIES 3
LinusH
Tourmaline | Level 20

Assuming that state has logical (and unbreakable) path.

Also assuming that state is global, the order is the same independent of id, or...?

If so, create a lookup table with a your state and a numerical order by variable, merge/join to get this order by variable, and then resort.

Data never sleeps
sleretrano
Quartz | Level 8
Thank you for your time.
Yes, assume that there always is a "proper" path.

I'm not sure I understand your question, The ordering, by descending priority is: ID, Time, Path.

Can you please provide the code to your suggestion?
LinusH
Tourmaline | Level 20
Nothing fancy just like:
Create table want as
Select have.*
From have
Inner join state_lookup
On have.initial_state = state_lookup.state
Order by state_lookup.state_order
;
Data never sleeps

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 723 views
  • 0 likes
  • 2 in conversation