Date: Wed, 5 Nov 2003 10:52:25 -0500
Reply-To: "Cacialli, Doug" <Doug_Cacialli@URMC.ROCHESTER.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Cacialli, Doug" <Doug_Cacialli@URMC.ROCHESTER.EDU>
Subject: Re: Retain statment
Content-Type: text/plain
This works, though it could be done more efficiently. Though not until my
pot of coffee finishes brewing.
data work.testset;
input ID DATE date10. DIAGNOSE $3.;
datalines;
01 11mar2002 250
01 19mar2002 410
01 20apr2002 410
02 10jun2002 410
02 11jul2002 250
03 12jun2002 410
03 10aug2002 410
;
run;
proc sort data = work.testset;
by ID DATE;
run;
data work.prevdx;
set work.testset;
by ID DATE;
retain DIABETES INF_DIAB;
if ((first.ID) and
(DIAGNOSE ^= '250'))
then DIABETES = 0;
else if (DIAGNOSE = '250')
then DIABETES = 1;
if (first.ID)
then INF_DIAB = 0;
else if ((DIAGNOSE = '410') and
(DIABETES = 1))
then INF_DIAB = 1;
run;
proc print data = work.prevdx;
var ID DATE DIAGNOSE INF_DIAB;
run;
Doug out.
-----Original Message-----
From: JannickeI [mailto:jannickei@HOTMAIL.COM]
Sent: Wednesday, November 05, 2003 9:53 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Retain statment
I have a file that contains information about patients and diagnoses. The
file looks like this:
PATIENT DATE DIAGNOSE
01 03-11-02 250
01 03-19-02 410
01 04-20-02 410
02 06-10-02 410
02 07-11-02 250
03 06-12-02 410
03 08-10-02 410
The date has format MM-DD-YY in the table above.
DIAGNOSE=250: Diabetes
DIAGNOSE=410: Heart attack
The data is sorted by patient and date.
I want to know if some of the patients with heart attack (410) have been
diagnosed with diabetes (250) BEFORE the heart attack.
In this case it's only patient 01. Patient 02 was diagnosed with diabetes
after the heart attack.
I want a new variable called INF_DIAB with the value 1 if the patient has
DIAGNOSE=410 and has been diagnosed with DIAGNOSE=250 before.
PATIENT DATE DIAGNOSE INF_DIAB
01 03-11-02 250 0
01 03-19-02 410 1
01 04-20-02 410 1
02 06-10-02 410 0
02 07-11-02 250 0
03 06-12-02 410 0
03 08-10-02 410 0
I think I should use the retain statment, but I don't know how.....
Jannicke