Date: Tue, 29 Nov 2011 11:12:26 -0800
Reply-To: "Choate, Paul@DDS" <Paul.Choate@DDS.CA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Choate, Paul@DDS" <Paul.Choate@DDS.CA.GOV>
Subject: Re: aggregating claims into inpatient treatment episodes
Content-Type: text/plain; charset="us-ascii"
For quick adhoc work of this sort I'll usually approach like this: create a loop for the days of the study and then test each service date range for every day of interest. From this create an in-service record sequence with y/n or 0/1 for every study day for every patient. Sort & undup it and use first. and last. logic to accumulate the ranges.
There's many ways to achieve the same, but given how messy claims can be the above is very clear albeit brute force approach. You can summarize by day rather than unduplicate if you are rolling up claims by episode. i.e. assign the claim to the first or last day of tx and then accumulate overlapping episodes from the sequence.
In production I'd use either arrays like Mary or SQL like Toby or perhaps a hash if it's very slow.
Hope that helps
DDS Data Extraction
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Simon, Lorna
Sent: Friday, November 18, 2011 7:03 AM
Subject: aggregating claims into inpatient treatment episodes
I have a claims dataset that I need to condense into 1 treatment episode - there can be many claims for each treatment episode (1 hospitalization). I found code in the archives which does this for most of the claims. However, for some hospitalizations, the claims are not consecutive - some of the hospitalizations may have claims which overlap.
Here are the data I have:
Obsnum project_id from_date to_date
1 1 1/1/2007 1/20/2007
2 2 6/30/2008 7/2/2008
3 2 7/3/2008 7/5/2008
4 3 9/9/2009 9/14/2009
5 3 9/10/2009 9/16/2009
Data I want:
project_id adm_date dis_date
1 1/1/2007 1/20/2007
2 6/30/2008 7/5/2008
3 9/9/2009 9/16/2009
Here is my code:
proc sort data=mhub92inpatientclaims; by project_id from_date to_date; run;
by project_id from_date;
lagto = lag(to_date);
if first.project_id then do;
lagto = .;
stay = 1;
if from_date-lagto ge 2 then stay + 1;
if from_date ge lagfrom and to_date le lagto then stay=lagstay;
format lagto lagfrom from_date to_date mmddyy10.;
by project_id stay;
if first.stay then adm_date = from_date;
the code works for project_ids 1 and 2, but not for project_id 3. I am still getting 2 lines for project_id, one with a treatment episode from 9/9/2009-9/9/14 and one with a treatment episode from 9/10/2009-9/16/2009 . the highlighted code is what I added to the code I found on the web in the hope of solving this problem, but obviously it is not working.
Any suggestions would be appreciated. Thanks.