BookmarkSubscribeRSS Feed
JohnPura
Calcite | Level 5

Hello SAS Users,

I'd like some help setting up a table for analysis. Currently the table looks like the one immediately below:


Each ID is associated with an ENTRY and EXIT time, which are bounded by LEFT and RIGHT limits. The ID's status will vary in each interval. Now, I'd like to arrange the data so that FOR EACH ID, I only have one set of unique left and right values. For instance, for ID = B, the first three lines have left = 0 and right = 0.5. I don't really care about the subintervals between the left and right limits of 0 and 0.5. However, for the last listing of left = 0 and right = 0.5, I want to preserve the value of the STATUS variable. For the 4th line (ID = A, Status = 1, Entry = 0.5, and Exit = 0.67077), I want to keep it as is because the EXIT value never reached the RIGHT value. I've created a table below the first to show what I would like to achieve.

ID

StatusEntryExitLeftRight
A00.000000.035590.00.5
A00.035590.128680.00.5
A10.128680.500000.00.5
A10.500000.670770.51.0
B10.000000.106780.00.5
B10.106780.500000.00.5
B10.500001.000000.51.0
B11.000001.500001.01.5
B11.500001.995891.52.0
B11.995892.000001.52.0
B12.000002.119102.02.5
B12.119102.494182.02.5

This is the table I want:

IDStatusEntryExitLeftRight
A100.500000.00.5
A10.500000.670770.51.0
B100.500000.00.5
B10.500001.000000.51.0
B11.000001.500001.01.5
B11.52.000001.52.0
B122.494182.02.5

Thanks for your help!

John

1 REPLY 1
Dreamer
Obsidian | Level 7

proc sort data=input;by id left right; run;

data want;

set input;

by id left right;

retain temp_entry;

if first.left then temp_entry=entry;

if last.left and last.right then do;

    entry=temp_entry;

    output;

end;

drop temp_entry;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1038 views
  • 3 likes
  • 2 in conversation