|Date: ||Thu, 22 Sep 2011 07:16:03 -0700|
|Reply-To: ||"Pardee, Roy" <pardee.r@GHC.ORG>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||"Pardee, Roy" <pardee.r@GHC.ORG>|
|Subject: ||Re: Comparing Variable Date Ranges Across Records to Define a New
|Content-Type: ||text/plain; charset="us-ascii"|
Just air-coding here (hint: include an executable data step w/your pretend data to get more work out of us ;-) but maybe something like:
proc sql ;
create table want as
select distinct d.*
when d.setting = 'IP' then 'IP'
when d.setting = 'ER' and lookahead.setting = 'IP' and (lookahead.admit_date -1) = d.admit_date then 'ER-IP'
when d.setting = 'AMB' and lookahead.setting = 'IP' then 'AMB-IP'
when d.setting = 'AMB' and lookahead.setting = 'ER' then 'AMB-ER'
end as new_setting
from have as d left join
have as lookahead
on d.pat_id = lookahead.pat_id AND
lookahead.admit_date between (d.admit_date + 1) and (d.admit_date + 3)
Play with that & make sure it does what you want & doesn't e.g., produce too many records.
I think you've got an ambiguity in your rules there--if you have AMB, then ER, then IP all w/in 1 day of each other, should the AMB be AMB-ER or AMB-IP?
Roy Pardee | DATA WRANGLER
Group Health Research Institute
PHONE 360-447-8773 | 206-287-2078
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Lauren
Sent: Wednesday, September 21, 2011 11:56 AM
Subject: Comparing Variable Date Ranges Across Records to Define a New Var
I have a dataset with patients, admission dates, and admission settings.
Patients and admit dates are distinct. The number of admissions per patient varies.
For each patient's admission, I want to define a new variable, new_setting, taking into account both the current record's setting and that of any admission occurring within the 1-3 days following. Specifically, the rules are
- if admit is inpatient (IP), new_setting = IP
- else if admit is to emergency room (ER) and there's an IP admit on the next day, new_setting = ER IP. Else new_setting = 'ER'
- if admit to ambulatory facility (AMB), look forward three days from admit, if there's an IP event this date range, new_setting = AMB-IP or if there's an ER event in this date range, new_setting = AMB-ER. Else new_setting = 'AMB'
My data looks something like this:
Patient Admit_date Setting
XXXXXX 1/1/2009 ER
XXXXXX 1/2/2009 IP
XXXXXX 1/5/2009 AMB
XXXXXX 1/7/2009 IP
I'd like it to look like this eventually:
Patient Admit_date Setting New_setting
XXXXXX 1/1/2009 ER ER-IP
XXXXXX 1/2/2009 IP IP
XXXXXX 1/5/2009 AMB AMB-IP
XXXXXX 1/7/2009 IP IP
I'm wondering if I have to transpose and use arrays? Any suggestion is welcome. Thank you in advance for your help!
Group Health is people-powered. Learn more at http://www.ghc.org/annualmeeting
GHC Confidentiality Statement
This message and any attached files might contain confidential information protected by federal and state law. The information is intended only for the use of the individual(s) or entities originally named as addressees. The improper disclosure of such information may be subject to civil or criminal penalties. If this message reached you in error, please contact the sender and destroy this message. Disclosing, copying, forwarding, or distributing the information by unauthorized individuals or entities is strictly prohibited by law.