Date: Thu, 5 Jan 2012 10:22:37 -0500
Reply-To: "Bian, Haikuo" <HBian@FLQIO.SDPS.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Bian, Haikuo" <HBian@FLQIO.SDPS.ORG>
Subject: Re: Flagging dose change
In-Reply-To: <CABOqZsz4106ZxMzncZaH=wY2KR68dcjMb_vTcCrQpCb6fFCQNg@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"
I did not read your time part of visitdttm.
Please try this:
data have;
input sub:$6. visitdttm :e8601da10. @28 cons 3. @32 day 2. dose:$3.;
cards;
ATNX11 2002-01-10 00:00:00 2.6 1 4
ATNX11 2002-01-10 00:00:00 2.6 2 4
ATNX11 2002-01-10 00:00:00 2.6 3 5.7
ATNX11 2002-01-10 00:00:00 2.6 4 5.3
ATNX11 2002-01-10 00:00:00 2.6 5 4
ATNX11 2002-01-10 00:00:00 2.6 6 4
ATNX11 2002-01-10 00:00:00 2.6 7 4
ATNX11 2002-03-06 00:00:00 1.2 1 4
ATNX11 2002-03-06 00:00:00 1.2 2 4
ATNX11 2002-03-06 00:00:00 1.2 3 4
ATNX11 2002-03-06 00:00:00 1.2 4 4
ATNX11 2002-03-06 00:00:00 1.2 5 4
ATNX11 2002-03-06 00:00:00 1.2 6 4
ATNX11 2002-03-06 00:00:00 1.2 7 4
ATNX33 2002-02-11 00:00:00 1.7 1 5
ATNX33 2002-02-11 00:00:00 1.7 2 5
ATNX33 2002-02-11 00:00:00 1.7 3 5
ATNX33 2002-02-11 00:00:00 1.7 4 0
ATNX33 2002-02-11 00:00:00 1.7 5 0
ATNX33 2002-02-11 00:00:00 1.7 6 5
ATNX33 2002-02-11 00:00:00 1.7 7 5
ATNX33 2002-03-28 00:00:00 1.7 1 5
ATNX33 2002-03-28 00:00:00 1.7 2 5
ATNX33 2002-03-28 00:00:00 1.7 3 5
ATNX33 2002-03-28 00:00:00 1.7 4 5
ATNX33 2002-03-28 00:00:00 1.7 5 7.5
ATNX33 2002-03-28 00:00:00 1.7 6 5
ATNX33 2002-03-28 00:00:00 1.7 7 5
;;;;
run;
proc sort data=have;
by sub visitdttm ;
run;
data want (drop=_:);
set have;
by sub visitdttm;
retain flag _dose;
length flag $3.;
if first.sub then _dose=dose;
if _dose ne dose then
do;
flag='YES';
_dose=dose;
end;
else flag='NO';
run;
proc print;run;
Kindly Regards,
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of sas quest
Sent: Thursday, January 05, 2012 9:55 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Flagging dose change
Hi all,
I have the following dataset where I have to create a flag whenever
dose changes. My code below doesnt work for sub=ATNX33 and
visitdttm=2002-02-11 00:00:00 because i didnt sort it by day. When i
sort by day the logic is not working.
I want it to be flagged like this
Sub Visitdttm Cons Day Dose Flag
ATNX11 2002-01-10 00:00:00 2.6 1 4 No
ATNX11 2002-01-10 00:00:00 2.6 2 4 No
ATNX11 2002-01-10 00:00:00 2.6 3 5.7 Yes
ATNX11 2002-01-10 00:00:00 2.6 4 5.3 Yes
ATNX11 2002-01-10 00:00:00 2.6 5 4 No
ATNX11 2002-01-10 00:00:00 2.6 6 4 No
ATNX11 2002-01-10 00:00:00 2.6 7 4 No
ATNX11 2002-03-06 00:00:00 1.2 1 4 No
ATNX11 2002-03-06 00:00:00 1.2 2 4 No
ATNX11 2002-03-06 00:00:00 1.2 3 4 No
ATNX11 2002-03-06 00:00:00 1.2 4 4 No
ATNX11 2002-03-06 00:00:00 1.2 5 4 No
ATNX11 2002-03-06 00:00:00 1.2 6 4 No
ATNX11 2002-03-06 00:00:00 1.2 7 4 No
ATNX33 2002-02-11 00:00:00 1.7 1 5 No
ATNX33 2002-02-11 00:00:00 1.7 2 5 No
ATNX33 2002-02-11 00:00:00 1.7 3 5 No
ATNX33 2002-02-11 00:00:00 1.7 4 0 Yes
ATNX33 2002-02-11 00:00:00 1.7 5 0 Yes
ATNX33 2002-02-11 00:00:00 1.7 6 5 No
ATNX33 2002-02-11 00:00:00 1.7 7 5 No
ATNX33 2002-03-28 00:00:00 1.7 1 6 No
ATNX33 2002-03-28 00:00:00 1.7 2 6 No
ATNX33 2002-03-28 00:00:00 1.7 3 6 No
ATNX33 2002-03-28 00:00:00 1.7 4 6 No
ATNX33 2002-03-28 00:00:00 1.7 5 7.5 Yes
ATNX33 2002-03-28 00:00:00 1.7 6 6 No
ATNX33 2002-03-28 00:00:00 1.7 7 6 No
data have;
input sub:$6. visitdttm &$19. @28 cons 3. @32 day 2. dose:$3.;
cards;
ATNX11 2002-01-10 00:00:00 2.6 1 4
ATNX11 2002-01-10 00:00:00 2.6 2 4
ATNX11 2002-01-10 00:00:00 2.6 3 5.7
ATNX11 2002-01-10 00:00:00 2.6 4 5.3
ATNX11 2002-01-10 00:00:00 2.6 5 4
ATNX11 2002-01-10 00:00:00 2.6 6 4
ATNX11 2002-01-10 00:00:00 2.6 7 4
ATNX11 2002-03-06 00:00:00 1.2 1 4
ATNX11 2002-03-06 00:00:00 1.2 2 4
ATNX11 2002-03-06 00:00:00 1.2 3 4
ATNX11 2002-03-06 00:00:00 1.2 4 4
ATNX11 2002-03-06 00:00:00 1.2 5 4
ATNX11 2002-03-06 00:00:00 1.2 6 4
ATNX11 2002-03-06 00:00:00 1.2 7 4
ATNX33 2002-02-11 00:00:00 1.7 1 5
ATNX33 2002-02-11 00:00:00 1.7 2 5
ATNX33 2002-02-11 00:00:00 1.7 3 5
ATNX33 2002-02-11 00:00:00 1.7 4 0
ATNX33 2002-02-11 00:00:00 1.7 5 0
ATNX33 2002-02-11 00:00:00 1.7 6 5
ATNX33 2002-02-11 00:00:00 1.7 7 5
ATNX33 2002-03-28 00:00:00 1.7 1 5
ATNX33 2002-03-28 00:00:00 1.7 2 5
ATNX33 2002-03-28 00:00:00 1.7 3 5
ATNX33 2002-03-28 00:00:00 1.7 4 5
ATNX33 2002-03-28 00:00:00 1.7 5 7.5
ATNX33 2002-03-28 00:00:00 1.7 6 5
ATNX33 2002-03-28 00:00:00 1.7 7 5
;;;;
run;
proc sort data=have;
by sub visitdttm cons dose day ;
run;
data want;
set have;
retain flag;
by sub visitdttm cons dose day ;
if first.dose then flag= "yes";
if first.visitdttm then flag = "no";
run;
Thanks in advance.
-----------------------------------------
Email messages cannot be guaranteed to be secure or error-free as
transmitted information can be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The
Centers for Medicare & Medicaid Services therefore does not accept
liability for any error or omissions in the contents of this
message, which arise as a result of email transmission.
CONFIDENTIALITY NOTICE: This communication, including any
attachments, may contain confidential information and is intended
only for the individual or entity to which it is addressed. Any
review, dissemination, or copying of this communication by anyone
other than the intended recipient is strictly prohibited. If you
are not the intended recipient, please contact the sender by reply
email and delete and destroy all copies of the original message.