From: olivesecret on
I have a data set consisting of obs for many subjects, with about 8
obs for each subject (at 8 time points, one obs/time). Ideally the obs
for each subject should be non-increasing over time. If any obs is not
in the non-increasing order, I need flag it. For example, obs for
subject 1 are:
subject res time
1 500 0
1 450 1
1 470 2
1 400 3
1 350 4
1 350 5
1 300 6
1 100 7

Since the 3rd obs >2nd obs, I need flag 3rd. So it looks like I need
compare each pair of continuous obs such as 1 vs 2, 2 vs. 3, ..., and
so on. How can I do it? Any suggestion is highly appreciated!
From: Paige Miller on
On Mar 30, 10:16 am, olivesecret <olivesec...(a)gmail.com> wrote:
> I have a data set consisting of obs for many subjects, with about 8
> obs for each subject (at 8 time points, one obs/time). Ideally the obs
> for each subject should be non-increasing over time. If any obs is not
> in the non-increasing order, I need flag it. For example, obs for
> subject 1 are:
> subject res time
> 1          500   0
> 1          450   1
> 1          470   2
> 1          400   3
> 1          350   4
> 1          350   5
> 1          300   6
> 1          100   7
>
> Since the 3rd obs >2nd obs, I need flag 3rd. So it looks like I need
> compare each pair of continuous obs such as 1 vs 2, 2 vs. 3, ..., and
> so on. How can I do it? Any suggestion is highly appreciated!

Use the data step LAG function.

--
Paige Miller
paige\dot\miller \at\ kodak\dot\com
From: Reeza on
On Mar 30, 7:16 am, olivesecret <olivesec...(a)gmail.com> wrote:
> I have a data set consisting of obs for many subjects, with about 8
> obs for each subject (at 8 time points, one obs/time). Ideally the obs
> for each subject should be non-increasing over time. If any obs is not
> in the non-increasing order, I need flag it. For example, obs for
> subject 1 are:
> subject res time
> 1          500   0
> 1          450   1
> 1          470   2
> 1          400   3
> 1          350   4
> 1          350   5
> 1          300   6
> 1          100   7
>
> Since the 3rd obs >2nd obs, I need flag 3rd. So it looks like I need
> compare each pair of continuous obs such as 1 vs 2, 2 vs. 3, ..., and
> so on. How can I do it? Any suggestion is highly appreciated!

Manually in a datastep:
Use a by "subject" and the retain to keep the last value in record.
Then compare the current value to the prior value.