Discussion:
SPSS remove cases in between times
(too old to reply)
m***@hotmail.com
2018-11-29 13:47:53 UTC
Permalink
I have a large data set. 100,000+ cases.
I want the oldest and newest cases per day by tempID.

In the data set, each day I may have 20 cases with the same ID and I only want to keep the oldest case and the newest case per day.
How do I write the syntax?

Example:
ID DATE TIME
39 21-Aug-2016 9:59:01.00
39 21-Aug-2016 9:59:05.00
39 23-Oct-2016 9:58:08.00
39 23-Oct-2016 9:58:34.00
39 23-Oct-2016 9:59:34.00
39 23-Oct-2016 10:00:04.100
39 23-Oct-2016 10:00:35.00
39 23-Oct-2016 10:01:05.00
39 19-Nov-2016 7:19:40.100
39 19-Nov-2016 7:20:12.00
39 19-Nov-2016 7:20:42.00
39 19-Nov-2016 7:21:36.00
39 19-Nov-2016 7:29:17.00
39 19-Nov-2016 7:29:49.00
39 19-Nov-2016 7:30:17.100
39 19-Nov-2016 7:32:47.00
39 19-Nov-2016 7:33:47.00
39 19-Nov-2016 7:34:42.100

Help would be greatly appreciated.
Bruce Weaver
2018-11-29 15:14:24 UTC
Permalink
Post by m***@hotmail.com
I have a large data set. 100,000+ cases.
I want the oldest and newest cases per day by tempID.
In the data set, each day I may have 20 cases with the same ID and I only want to keep the oldest case and the newest case per day.
How do I write the syntax?
ID DATE TIME
39 21-Aug-2016 9:59:01.00
39 21-Aug-2016 9:59:05.00
39 23-Oct-2016 9:58:08.00
39 23-Oct-2016 9:58:34.00
39 23-Oct-2016 9:59:34.00
39 23-Oct-2016 10:00:04.100
39 23-Oct-2016 10:00:35.00
39 23-Oct-2016 10:01:05.00
39 19-Nov-2016 7:19:40.100
39 19-Nov-2016 7:20:12.00
39 19-Nov-2016 7:20:42.00
39 19-Nov-2016 7:21:36.00
39 19-Nov-2016 7:29:17.00
39 19-Nov-2016 7:29:49.00
39 19-Nov-2016 7:30:17.100
39 19-Nov-2016 7:32:47.00
39 19-Nov-2016 7:33:47.00
39 19-Nov-2016 7:34:42.100
Help would be greatly appreciated.
You can use the FIRST and LAST sub-commands for MATCH FILES to flag the first and last cases in a BY group. E.g.,

SORT CASES BY ID DATE TIME.
MATCH FILES FILE = * /
BY ID DATE /
FIRST = oldest /
LAST = newest.
EXECUTE.

Then you can set a filter to use only cases where oldest=1 or newest=1, or you can use SELECT IF to permanently drop cases that do not meet either of those conditions.
Loading...