BookmarkSubscribeRSS Feed
Maomao_Hui
Calcite | Level 5

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

DateIDstatecount
199801101
199802102
199803113
199804114
199805115
199806106
199801201
199802202
199803213
199804214
199805205
199806206
199807207
199808208
199809219
19980102110
19980112011
19980122012

 

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

NewDateIDstartstopstate
1997121020
1998021251
1998051560
1997122020
1998022241
1998042480
19980828101
199810210120

 

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

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Is Date an actual SAS Date value or just a number as posted?

PeterClemmensen
Tourmaline | Level 20

Also, a few of your date values have the form 1998010 ?

 

Is this an error or something we should account for?

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 630 views
  • 0 likes
  • 2 in conversation