BookmarkSubscribeRSS Feed
statadm
Fluorite | Level 6
I'm having trouble writing a program to define the lower and upper bounds in order to run a bunch of models using interval censoring.

Here are some sample data and what I need to do:

id point time
1 3 10:20
1 4 11:00
1 4 11:30
1 5 12:15
1 5 12:45
1 6 13:50
1 7 14:30
2 2 09:00
2 2 09:45
2 4 10:30
2 5 11:15
2 7 12:25


I want to run several models (which I don't need help with) looking at the time it takes for the points to change. Since we do not know the exact time, I want to use interval censoring. Therefore, my goal is the get the possible lower and upper time points for each change. The changes I want to look at are 2 to 3, 3 to 4, 4 to 5, 5 to 6, 6 to 7. I need the lower and upper possible time ranges for each of these changes. The time ranges will be the least possible time it took to change from 2 to 3 and the most possible time it took to change from 2 to 3 (in minutes).

So for ID 2, I know that the time falls somewhere between 09:45 and 10:30 (45 minutes). The bounds would then be 1-45.

I'm looking for a way to calculate the lower and upper bound for each point change.

Thanks in advance!
6 REPLIES 6
Peter_C
Rhodochrosite | Level 12
>
> I'm looking for a way to calculate the lower and
> upper bound for each point change.
>
> Thanks in advance!

the sophisticated subject seemed out of my range of knowledge, but..
it seems stataDM just seeks latest and earliest time values as an ID moves from one "point" to the next
That looks like an eaasy challenge for data step handling of retain and/or lag()/dif() functions and by-grouop processing, using a do loop with last.ID to collect info
For example :assuming "point" is numeric[pre]data changes ;
do /* loop over rows for an ID */ until( last.ID) ;
set stataDM.data ;
by ID ;
interval = dif( time) ;
if dif( point ) then /* have change in point */ do ;
if not first.ID then output ;
last_point= point ;
end ;
last_time= time ;
end ;
run ;[/pre]
The output will have an entry for each change of "point" for an ID with extra columns INTERVAL, LAST_POINT and LAST_TIME, which I think should provide what is needed.
Then in addition to what appeared to be asked for
> change. The changes I want to look at are 2 to 3, 3
> to 4, 4 to 5, 5 to 6, 6 to 7. I need the lower and

it will also provide that 45 interval for ID=2 where POINT changes from 2 to 4 indicated as expected output by this next piece of the original posting

> So for ID 2, I know that the time falls somewhere
> between 09:45 and 10:30 (45 minutes). The bounds
> would then be 1-45.
statadm
Fluorite | Level 6
I have revised this and hope to do this a different way. Here is the sample data:


id point time
1 3 0
1 4 30
1 4 60
1 5 90
1 5 120
1 6 150
1 7 210
2 2 0
2 2 60
2 4 120
2 5 180
2 7 210

So what I actually need to get using sample id 2, if I want to calculate the min and max time to go from 4 to 5 it would take [60-120] to get to 4 and [120-180] to get to 5. So, the minimum time would be 120-120=0 and maximum would be 180-60=120. My lower bound would be 0 and the upper bound would be 120.

Any thoughts on how to calculate this for each interval in SAS?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest the OP start with the SAS code piece replied from Peter.C, after digesting what it is doing - then come back to the forum if additional questions exist.

Scott Barry
SBBWorks, Inc.
statadm
Fluorite | Level 6
Well, I've completely changed what I need to do, so the code Peter suggested will not work for me.

Thanks for the suggestion.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The SAS programming fundamentals are pertinent which you can use and still relate to your objective, I would say - FIRST. and likely LAST. to correlate related SAS variable values, capturing TIME and then deriving a interval time measurement.

Scott Barry
SBBWorks, Inc.
statadm
Fluorite | Level 6
Thank you to Peter and Scott for your help. You both led me in the right direction. I ended up using arrays, but your suggestions helped me to get it right.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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