Date: Thu, 19 May 2011 08:32:12 -0400
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: Drug Switching
In-Reply-To: <201105191144.p4JAl4Oo000503@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
Dave;
Following code adopted 2XDUL, seems to work for you.
data in;
input pid drug date:mmddyy10.;
format date mmddyy10.;
cards;
1 1234 1/1/2010
1 1234 2/1/2010
1 1234 3/1/2010
2 34 3/5/2010
2 34 4/1/2010
2 45 5/2/2010
2 56 6/3/2010
3 55 4/1/2010
3 56 5/1/2010
3 57 6/1/2010
3 57 7/1/2010
4 123 6/3/2010
5 55 7/1/2010
5 55 7/24/2010
;
run;
data no_switch (drop=a b c flag) switched (drop=a b c flag);
retain a b flag;
do until (last.pid);
set in ;
by pid drug notsorted;
if first.pid then a=drug;
if last.pid then b=drug;
if a=b then flag=1;
else if a ne b then flag=0;
end;
do until (last.pid);
set in;
by pid drug notsorted;
if flag=1 and first.pid then output no_switch;
if first.drug and flag=0 then do;
c+1;
if c le 2 then output switched;
end;
end;
c=0;
run;
proc print;
run;
HTH,
Haikuo
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Dave
Sent: Thursday, May 19, 2011 7:45 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Drug Switching
Hi SAS-Lers
I need to find out which patient switched drugs and also if they switched
determine the first time they switched.
data in;
input pid drug date:mmddyy10.;
format date mmddyy10.;
cards;
1 1234 1/1/2010
1 1234 2/1/2010
1 1234 3/1/2010
2 34 3/5/2010
2 34 4/1/2010
2 45 5/2/2010
2 56 6/3/2010
3 55 4/1/2010
3 56 5/1/2010
3 57 6/1/2010
3 57 7/1/2010
4 123 6/3/2010
5 55 7/1/2010
5 55 7/24/2010
;
run;
Since pid 1, 4, and 5 never switched they would be outputted to NO_SWITCH
data set.
PID 2 had an initial switch from date 3/5/2010 and 5/2/2010; i.e., changed
drugs from 34 to 45. I need to output those two records to data set
SWITCHED.
PID 3 would output drug 55 and 56 to data set SWITCHED.
Any suggestions?
Thanks for your help.
Dave
-----------------------------------------
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.