Hi there,
I have the dataset "have" that record the state as follow, state=1 means the event happened, zeros otherwise.
The event may occur more than once over the follow-up time for a given subject.
I want to calculate the start and stop time for each event to get the dataset "want" as follow.
For example, the first event (state=0) of ID_1 start at 0 and end at 2.
Have
Date | ID | state | count |
199801 | 1 | 0 | 1 |
199802 | 1 | 0 | 2 |
199803 | 1 | 1 | 3 |
199804 | 1 | 1 | 4 |
199805 | 1 | 1 | 5 |
199806 | 1 | 0 | 6 |
199801 | 2 | 0 | 1 |
199802 | 2 | 0 | 2 |
199803 | 2 | 1 | 3 |
199804 | 2 | 1 | 4 |
199805 | 2 | 0 | 5 |
199806 | 2 | 0 | 6 |
199807 | 2 | 0 | 7 |
199808 | 2 | 0 | 8 |
199809 | 2 | 1 | 9 |
1998010 | 2 | 1 | 10 |
1998011 | 2 | 0 | 11 |
1998012 | 2 | 0 | 12 |
I want to get the start and stop time of each event for each subject. And the "Newdate" is following the start time as follow.
Want
NewDate | ID | start | stop | state |
199712 | 1 | 0 | 2 | 0 |
199802 | 1 | 2 | 5 | 1 |
199805 | 1 | 5 | 6 | 0 |
199712 | 2 | 0 | 2 | 0 |
199802 | 2 | 2 | 4 | 1 |
199804 | 2 | 4 | 8 | 0 |
199808 | 2 | 8 | 10 | 1 |
199810 | 2 | 10 | 12 | 0 |
data ISA.Have;
infile datalines missover;
input Date ID state count;
label ID='Subject ID';
datalines;
199801 1 0 1
199802 1 0 2
199803 1 1 3
199804 1 1 4
199805 1 1 5
199806 1 0 6
199801 2 0 1
199802 2 0 2
199803 2 1 3
199804 2 1 4
199805 2 0 5
199806 2 0 6
199807 2 0 7
199808 2 0 8
199809 2 1 9
1998010 2 1 10
1998011 2 0 11
1998012 2 0 12
;
Many thanks.
Regards,
Hui
Is Date an actual SAS Date value or just a number as posted?
Also, a few of your date values have the form 1998010 ?
Is this an error or something we should account for?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.