LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 16 Mar 2009 12:27:34 -0500
Reply-To:     Suhong Tong <sophidt@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Suhong Tong <sophidt@HOTMAIL.COM>
Subject:      Re: How to collapse consecutive visits
Comments: To: snoopy369@gmail.com
In-Reply-To:  <b7a7fa630903160908o23d0adfjee21c874c667fe9f@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Thank you, Joe.

You code works exactly as I expected!

Sophia

Date: Mon, 16 Mar 2009 11:08:36 -0500 Subject: Re: How to collapse consecutive visits From: snoopy369@gmail.com To: sophiDT@hotmail.com CC: SAS-L@listserv.uga.edu

Sophia, What do you consider adequately close together to be one A-D pair? Does it have to be a single day only (4/4 to 4/5) or can it be longer?

If it's just a single day difference, you can do this: data have; informat admit discharge MMDDYY10.; informat id $12.; input ID $ admit discharge ; datalines; 90179392E 7/18/2007 7/18/2007 90256373a 9/7/2007 9/7/2007 90256373a 11/6/2007 11/6/2007 90256373a 11/7/2007 11/7/2007 90256373a 12/2/2007 12/2/2007 90256373a 12/3/2007 12/3/2007 90256373a 12/4/2007 12/4/2007 90256373a 12/5/2007 12/5/2007 90256373a 12/6/2007 12/6/2007 90256373a 12/7/2007 12/7/2007 90256373a 12/8/2007 12/8/2007 90256373a 4/10/2008 4/10/2008 90256373a 4/11/2008 4/11/2008 90256373a 4/12/2008 4/12/2008 90256373a 4/13/2008 4/13/2008 90256373a 4/14/2008 4/14/2008 90256373a 4/15/2008 4/15/2008 90256373a 4/16/2008 4/16/2008 90294928A 4/7/2008 4/7/2008 90294928A 4/7/2008 4/11/2008 90536782A 4/10/2008 4/10/2008 90536782A 4/11/2008 4/11/2008 90536782A 4/12/2008 4/12/2008 90536782A 4/13/2008 4/13/2008 90536782A 4/14/2008 4/14/2008 90536782A 4/15/2008 4/15/2008 90536782A 4/16/2008 4/16/2008 ;;;;; run;

proc sort data=have; by id admit; run;

data want; retain prev_dschg first_admit; keep id first_admit final_dschg; set have; by id admit; if first.id or last.id then do; if first.id then do; first_admit = admit; end; if last.id then do; final_dschg = discharge; output; end; end; else do; if prev_dschg < admit - 1 then do; final_dschg = prev_dschg; output; first_admit = admit; call missing(final_dschg); end; *else output; end; prev_dschg = discharge; run;

and then merge that dataset back onto the regular dataset. I imagine a double DoW loop could do it a bit more efficiently but I'm not entirely sure how to do that when there's possibly multiple 'by groups' per actual by group.

-Joe

On Mon, Mar 16, 2009 at 10:31 AM, Sophia Tong <sophiDT@hotmail.com> wrote:

Dear listers,

I have a admission - discharge data of patients. There are situations that a patient had back to back admission - discharge, in that case, it should count as one admission-discharge. I am truggling how to flag them out. Below are the data I have and the outcome data I want.

Thanks in advance,

Sophia

Data have: ID admit discharge 90179392E 7/18/2007 7/18/2007 90256373a 9/7/2007 9/7/2007 90256373a 11/6/2007 11/6/2007 90256373a 11/7/2007 11/7/2007 90256373a 12/2/2007 12/2/2007 90256373a 12/3/2007 12/3/2007 90256373a 12/4/2007 12/4/2007 90256373a 12/5/2007 12/5/2007 90256373a 12/6/2007 12/6/2007 90256373a 12/7/2007 12/7/2007 90256373a 12/8/2007 12/8/2007 90256373a 4/10/2008 4/10/2008 90256373a 4/11/2008 4/11/2008 90256373a 4/12/2008 4/12/2008 90256373a 4/13/2008 4/13/2008 90256373a 4/14/2008 4/14/2008 90256373a 4/15/2008 4/15/2008 90256373a 4/16/2008 4/16/2008 90294928A 4/7/2008 4/7/2008 90294928A 4/7/2008 4/11/2008 90536782A 4/10/2008 4/10/2008 90536782A 4/11/2008 4/11/2008 90536782A 4/12/2008 4/12/2008 90536782A 4/13/2008 4/13/2008 90536782A 4/14/2008 4/14/2008 90536782A 4/15/2008 4/15/2008 90536782A 4/16/2008 4/16/2008

data want:

ID admit discharge AD DC 90179392E 7/18/2007 7/18/2007 7/18/2007 7/18/2007 90256373a 9/7/2007 9/7/2007 9/7/2007 9/7/2007 90256373a 11/6/2007 11/6/2007 11/6/2007 11/7/2007 90256373a 11/7/2007 11/7/2007 90256373a 12/2/2007 12/2/2007 12/2/2007 12/8/2007 90256373a 12/3/2007 12/3/2007 90256373a 12/4/2007 12/4/2007 90256373a 12/5/2007 12/5/2007 90256373a 12/6/2007 12/6/2007 90256373a 12/7/2007 12/7/2007 90256373a 12/8/2007 12/8/2007 90256373a 4/10/2008 4/10/2008 4/10/2008 4/16/2008 90256373a 4/11/2008 4/11/2008 90256373a 4/12/2008 4/12/2008 90256373a 4/13/2008 4/13/2008 90256373a 4/14/2008 4/14/2008 90256373a 4/15/2008 4/15/2008 90256373a 4/16/2008 4/16/2008 90294928A 4/7/2008 4/7/2008 4/7/2008 4/11/2008 90294928A 4/7/2008 4/11/2008 90536782A 4/10/2008 4/10/2008 4/10/2008 4/16/2008 90536782A 4/11/2008 4/11/2008 90536782A 4/12/2008 4/12/2008 90536782A 4/13/2008 4/13/2008 90536782A 4/14/2008 4/14/2008 90536782A 4/15/2008 4/15/2008 90536782A 4/16/2008 4/16/2008

_________________________________________________________________ HotmailŪ is up to 70% faster. Now good news travels really fast. http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009


Back to: Top of message | Previous page | Main SAS-L page