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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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