compare different rows in differrent var

  • Follow


Hi, I have data set like this:

data have;
input v1 v2;
Datalines;
1 2
4 .
0 .
0 .
5 .
2 .
1 .
;

data want;

	 set have;

	*  if v1 < v2 then true_false = 1;
run;

I need to compare  2nd row of v1 to 1st row of v2. After the 1st
comparison based on true false,  the value will be filled in 2nd row
of v2, and then compare 3rd row of v1 to 2nd row of v2 and so on....
Could anyone help me how to do that ?

Thanks, D


0
Reply db 2/7/2011 10:05:12 AM

On Feb 7, 2:05=A0am, db <daronnebonn...@gmail.com> wrote:
> Hi, I have data set like this:
>
> data have;
> input v1 v2;
> Datalines;
> 1 2
> 4 .
> 0 .
> 0 .
> 5 .
> 2 .
> 1 .
> ;
>
> data want;
>
> =A0 =A0 =A0 =A0 =A0set have;
>
> =A0 =A0 =A0 =A0 * =A0if v1 < v2 then true_false =3D 1;
> run;
>
> I need to compare =A02nd row of v1 to 1st row of v2. After the 1st
> comparison based on true false, =A0the value will be filled in 2nd row
> of v2, and then compare 3rd row of v1 to 2nd row of v2 and so on....
> Could anyone help me how to do that ?
>
> Thanks, D

"the value will be filled in 2nd row of v2", the value means value of
v1? Or the true_false value?
What happens if comparison is false? What value will be filled in for
v2?
Can you post you expected result based on your sample data?


0
Reply Ya 2/7/2011 3:41:30 PM


D,
I think you can achieve this with a lag function. I don't see why you
need to save a true-false variable, so I left it out.  Hope this
helps.

Data want;
   Set have;
   if v1 lt lag(v2) then v2=lag(v2);
     *otherwise v2 keeps its original value;


0
Reply TKeyes 2/7/2011 9:34:51 PM

2 Replies
221 Views

(page loaded in 0.058 seconds)

Similiar Articles:













7/29/2012 7:09:15 PM


Reply: