How to only keep the latest observations with different settings and the same subject number?

Reply
Occasional Contributor
Posts: 9

How to only keep the latest observations with different settings and the same subject number?

Hello everyone,

I am attempting to only keep the relevant data in my data set, and I am having some trouble. I want to only keep the latest alert setting information for each subject when there was a new setting.

Here is an example of the data set I am using:

obs     subject          receiver        #     device time               low   hi               receiver time

1SM21666728SM21666728201JAN2009:00:00:13802003301JAN2009:00:00:13
2SM21666728SM21666728002JAN2009:02:46:44802003302JAN2009:02:46:44
3SM21666728SM21666728102JAN2009:02:53:26802003302JAN2009:02:53:26
4SM21666728SM21666728302JAN2009:02:53:27802003302JAN2009:02:53:27
5SM21666728SM21666728402JAN2009:10:14:34802003302JAN2009:10:14:34
6SM21666728SM21666728626APR2012:05:34:55802003325APR2012:22:34:55
7SM21666728SM21666728726APR2012:05:34:56802003325APR2012:22:34:56
8SM21666728SM21666728826APR2012:05:34:57802003325APR2012:22:34:57
9SM21666728SM21666728926APR2012:05:38:31802003325APR2012:22:38:31
10SM21666728SM216667281026APR2012:05:38:40802003325APR2012:22:38:40
11SM21666728SM216667281226APR2012:05:38:41802003325APR2012:22:38:41
12SM21666728SM21666728526APR2012:05:34:55802003326APR2012:05:34:55
13SM21666728SM216667281413DEC2012:17:59:00802003313DEC2012:10:59:00
14SM21666728SM216667281713DEC2012:17:59:30802003313DEC2012:10:59:30
15SM21666728SM216667281813DEC2012:17:59:31802003313DEC2012:10:59:31
16SM21666728SM216667281913DEC2012:17:59:32802003313DEC2012:10:59:32
17SM21666728SM216667282014DEC2012:17:37:41802003314DEC2012:10:37:41
18SM21666728SM216667282114DEC2012:17:38:57802003314DEC2012:10:38:57
19SM21666728SM216667282215DEC2012:21:26:54802003315DEC2012:14:26:54
20SM21666728SM216667282315DEC2012:21:28:15802003315DEC2012:14:28:15
21SM21666728SM216667282416DEC2012:05:40:49802203315DEC2012:22:40:49
22SM21666728SM216667282516DEC2012:05:41:101002203315DEC2012:22:41:10

So for example, I would only want to keep obs 20, 21, and 22 since they are the ones which have different settings. In reality, I would like to keep the very last occurrence of that setting, but in this example lets just pretend the data set stops at 22. Also, these are all observations for the same subject number... I need a way to do these for each unique subject number.

I have a deadline today and could really use some help ASAP! Thank you guys so much. This is such a great community.

-Tyler

Grand Advisor
Posts: 10,196

Re: How to only keep the latest observations with different settings and the same subject number?

You mention "last occurrence of that setting" but I don't see anything that is obviously related to setting. If you are talking about combinations of LOW and HI this MIGHT do what you want;

proc sort data=have; by subject receiver device_time low hi;

data want ;

     set have;

     by subject receiver low hi;

     if last.low or last.hi;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 132 views
  • 1 like
  • 2 in conversation