BookmarkSubscribeRSS Feed
rsva
Fluorite | Level 6
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.
6 REPLIES 6
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
Peter_C
Rhodochrosite | Level 12
Rsva
what should happen if an ID has more than two rows?
peterC
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello PeterC,

My code is taking care of these cases too.

SPR
Peter_C
Rhodochrosite | Level 12
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
rsva
Fluorite | Level 6
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.
rsva
Fluorite | Level 6
Thanks SPR it worked perfectly.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1809 views
  • 0 likes
  • 3 in conversation