- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 12-02-2010 09:06 AM
(2143 views)
I would like to compare a value between two rows. For e.g. I have duplicate id numbers in Column A, DOB in Column B, and state in Column C.
Id DOB State
xx1 20061023 GA
xx1 20080115 GA
sd45 20050203 FL
sd45 20050203 FL
h5g 20060709 NV
h5g 20080115 NV
7uj 20071026 CA
7uj 20071026 CA
I want to check if DOB for the two (same) ids are same. If they are same I would like to code as 1 else code as 2.
Thanks in advance.
Id DOB State
xx1 20061023 GA
xx1 20080115 GA
sd45 20050203 FL
sd45 20050203 FL
h5g 20060709 NV
h5g 20080115 NV
7uj 20071026 CA
7uj 20071026 CA
I want to check if DOB for the two (same) ids are same. If they are same I would like to code as 1 else code as 2.
Thanks in advance.
6 REPLIES 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Rsva,
If I understood you correctly then this is a solution:
[pre]
data i;
input Id $ DOB State $;
datalines;
xx1 20061023 GA
xx1 20080115 GA
sd45 20050203 FL
sd45 20050203 FL
h5g 20060709 NV
h5g 20080115 NV
7uj 20071026 CA
7uj 20071026 CA
;
run;
proc sort data=i;
by ID DOB;
run;
data r;
set i;
if First.DOB=LAST.DOB then code=2;
if NOT (First.DOB = 1 and Last.DOB = 1) then code=1;
by ID DOB;
run;
[/pre]
Sincerely,
SPR
If I understood you correctly then this is a solution:
[pre]
data i;
input Id $ DOB State $;
datalines;
xx1 20061023 GA
xx1 20080115 GA
sd45 20050203 FL
sd45 20050203 FL
h5g 20060709 NV
h5g 20080115 NV
7uj 20071026 CA
7uj 20071026 CA
;
run;
proc sort data=i;
by ID DOB;
run;
data r;
set i;
if First.DOB=LAST.DOB then code=2;
if NOT (First.DOB = 1 and Last.DOB = 1) then code=1;
by ID DOB;
run;
[/pre]
Sincerely,
SPR
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Rsva
what should happen if an ID has more than two rows?
peterC
what should happen if an ID has more than two rows?
peterC
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello PeterC,
My code is taking care of these cases too.
SPR
My code is taking care of these cases too.
SPR
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
yes but SPR, you are assuming that a trio(or more) should be handled the same as a pair.
(making my own assumptions)
what if the third child is not the same age as the twins within the family ID?
hence, my question to the original poster
(making my own assumptions)
what if the third child is not the same age as the twins within the family ID?
hence, my question to the original poster
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your question Peter. I tried SPR's sample code and included third row for an id. It worked fine. When I added a third row,
Case1 (Coded as 2)
xx1 20061023 GA 2
xx1 20080115 GA 2
xx1 20100115 GA 2
Case2 (Codes twin as 1 and the other as 2)
sd45 20050203 FL 1
sd45 20050203 FL 1
sd45 20041023 FL 2
This is what my expected result was. Sorry for not being clear in my question.
Thanks a lot.
Case1 (Coded as 2)
xx1 20061023 GA 2
xx1 20080115 GA 2
xx1 20100115 GA 2
Case2 (Codes twin as 1 and the other as 2)
sd45 20050203 FL 1
sd45 20050203 FL 1
sd45 20041023 FL 2
This is what my expected result was. Sorry for not being clear in my question.
Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks SPR it worked perfectly.