|
|
compare different rows in differrent var
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: compare different rows in differrent var - comp.soft-sys.sas ...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... Compare values in different rows in different goups - comp.soft ...compare different rows in differrent var - comp.soft-sys.sas ... Compare values in different rows in different goups - comp.soft ... Groups ... compare different rows in ... Rotate Row Data - comp.soft-sys.sasGreetings- I have a data set with multiple rows for each clients and different variables in different columns like so: ID, Var1, Var2, Var3, Va... Compare cell and double variables - comp.soft-sys.matlab ...compare different rows in differrent var - comp.soft-sys.sas ... Compare cell and double variables - comp.soft-sys.matlab ... compare different rows in differrent var ... normalized cross correlation(NCC) - comp.soft-sys.matlab ...compare different rows in differrent var - comp.soft-sys.sas ... Hi, I would like to perform normalized cross correlation(NCC) using color images, this is how i am doing ... How to apply a alternate color pattern on rows in excel sheet ...compare different rows in differrent var - comp.soft-sys.sas ... How to apply a alternate color pattern on rows in excel sheet ... compare different rows in differrent var ... Math operations on fields of different rows - comp.lang.awk ...compare different rows in differrent var - comp.soft-sys.sas ... compare values in the same field in consecutive rows--and store ... Math operations on fields of different ... About LAG function in group(data;set; by;) - comp.soft-sys.sas ...compare different rows in differrent var - comp.soft-sys.sas ... Hi, I have data set like this: data have; input v1 ... D, I think you can achieve this with a lag function ... How to combine types from multiple rows - comp.soft-sys.sas ...compare different rows in differrent var - comp.soft-sys.sas ... How to combine types from multiple rows - comp.soft-sys.sas ... Dear S-L, I tried to combine type from ... compare different rows in differrent var - comp.soft-sys.sas ...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... compare different rows in differrent var - sas - Mofeel Groupssas, compare different rows in differrent var . comp.soft-sys.sas - The SAS statistics package. 7/29/2012 7:09:15 PM
|
|
|
|
|
|
|
|
|