From: Al on
Dear all:

This is the dataset i have ..


pat vis dt
1 1 11FEB2010
1 2 13FEB2010
1 3 14FEB2010
2 1 11MAR2010
2 2 06MAR2010
2 3 20MAR2010
3 1 05MAY2010
3 2 08MAY2010
3 3 12MAY2010
3 4 10MAY2010




I am trying to get to this dataset with a flag variable
to see if any of the dt values are placed out of the order per pat




pat vis dt flag
1 1 11FEB2010
1 2 13FEB2010
1 3 14FEB2010
2 1 11MAR2010 1
2 2 06MAR2010 1
2 3 20MAR2010
3 1 05MAY2010
3 2 08MAY2010
3 3 12MAY2010 1
3 4 10MAY2010 1


Any suggestions

Thanks in advance
Al
From: Arthur Tabachneck on
Al,

I think that the look ahead look back code proposed by Howard Schreier
a few years ago will do exactly what you want. E.g.,

data have;
format dt date9.;
informat dt date9.;
input pat vis dt date9.;
cards;
1 1 11FEB2010
1 2 13FEB2010
1 3 14FEB2010
2 1 11MAR2010
2 2 06MAR2010
2 3 20MAR2010
3 1 05MAY2010
3 2 08MAY2010
3 3 12MAY2010
3 4 10MAY2010
;

data want (drop=next: prev:);
set have;
by pat;
call missing(flag);
set have ( firstobs = 2 keep = dt
rename = (dt = next_dt) )
have ( obs = 1 drop = _all_ );
format prev_dt next_dt date9.;
prev_dt=lag(dt);
if last.pat then next_dt=.;
if (not(missing(next_dt)) and dt gt next_dt) or
dt lt prev_dt
then flag=1;
run;

HTH,
Art
------------
On Jul 7, 2:38 pm, Al <ali6...(a)gmail.com> wrote:
> Dear all:
>
> This is the dataset i have ..
>
> pat vis  dt
> 1    1   11FEB2010
> 1    2   13FEB2010
> 1    3   14FEB2010
> 2    1   11MAR2010
> 2    2   06MAR2010
> 2    3   20MAR2010
> 3    1   05MAY2010
> 3    2   08MAY2010
> 3    3   12MAY2010
> 3    4   10MAY2010
>
> I am trying to get to this dataset with a flag variable
> to see if any of the dt values are placed out of the order per pat
>
> pat vis  dt         flag
> 1    1   11FEB2010
> 1    2   13FEB2010
> 1    3   14FEB2010
> 2    1   11MAR2010   1
> 2    2   06MAR2010   1
> 2    3   20MAR2010
> 3    1   05MAY2010
> 3    2   08MAY2010
> 3    3   12MAY2010   1
> 3    4   10MAY2010   1
>
> Any suggestions
>
> Thanks in advance
> Al

 | 
Pages: 1
Prev: explode tails of histogram
Next: Print Settings