Date: Mon, 11 May 2009 06:27:43 -0400
Reply-To: Randy <randistan69@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Randy <randistan69@HOTMAIL.COM>
Subject: Flagging multiple ID's on the same day
I want to flag multiple ID's (where ID_A and ID_B are one unit) that appear
in different "Code" on the same day:
My data set is as follows
Date Code ID_A ID_B
May1 1 AB1 XZ
May1 1 AB1 MN
May1 2 AB1 XZ
May1 2 CD1 MN
May2 1 AB1 XZ
May2 1 CD1 MN
May2 2 CD1 MN
May2 2 AB1 MN
My output should be as follows:
Date Code ID_A ID_B Flag1
May1 1 AB1 XZ 1
May1 1 AB1 MN 0
May1 2 AB1 XZ 1
May1 2 CD1 MN 0
May2 1 AB1 XZ 0
May2 1 CD1 MN 1
May2 2 CD1 MN 1
May2 2 AB1 MN 0
The code that I wrote is as follows:
data need; set have;
by code ID_A ID_B date;
flag1 = 0;
if (first.ID_B and last.ID_B) then flag1 = 1;
run;
It does not work. What mistake am I making?
Randy