Hi,
I have a dataset that looks like follows: I want to get the latest start for the ID, i.e. if there are 2 starts in a day for an ID, I would like to keep the later start on that day.
DATA have:
ID Startdate Startdatetime
1 1/1/2000 1/1/2000 14:12:35
1 1/1/2000 1/1/2000 14:14:35
1 1/1/2000 1/1/2000 12:12:35
1 5/1/2000 5/1/2000 14:12:35
2 1/1/2000 1/1/2000 14:12:35
2 2/1/2000 2/1/2000 14:12:35
2 2/1/2000 2/1/2000 19:12:35
3 1/1/2000 1/1/2000 14:12:35
3 2/1/2000 2/1/2000 15:12:35
3 3/1/2000 3/1/2000 16:12:35
DATA Want:
ID Startdate Startdatetime
1 1/1/2000 1/1/2000 14:14:35
1 5/1/2000 5/1/2000 14:12:35
2 1/1/2000 1/1/2000 14:12:35
2 2/1/2000 2/1/2000 19:12:35
3 1/1/2000 1/1/2000 14:12:35
3 2/1/2000 2/1/2000 15:12:35
3 3/1/2000 3/1/2000 16:12:35
Here is what I tried:
PROC SORT DATA=have;
BY ID DESCENDING StartdateTime Startdate;
RUN;
DATA want;
SET have;
BY Startdate;
IF first.Startdate;
RUN;
The sort runs fine, however, I get an error "BY variable are not properly sorted."
Any ideas on getting it right? I am not sure where I am going wrong.
Thanks,