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 (September 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 5 Sep 2007 17:37:38 -0400
Reply-To:     Ya Huang <ya.huang@AMYLIN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ya Huang <ya.huang@AMYLIN.COM>
Subject:      Re: Merge question
Comments: To: olana98@GOOGLEMAIL.COM

Here is one without using proc sql:

Data one; input ID Visit :ddmmyy10.; cards; 19 31/07/2000 41 02/08/2000 52 02/08/2000 19 14/08/2000 ;

Data two; input Ref_date :ddmmyy10. Grp; cards; 31/07/2000 1 24/07/2000 0 17/07/2000 0 10/07/2000 0 03/07/2000 0 02/08/2000 1 09/08/2000 0 16/08/2000 0 23/08/2000 0 30/08/2000 0 14/08/2000 1 07/08/2000 0 21/08/2000 0 28/08/2000 0 ;

data two; set two; retain firstdt; if grp=1 then do; group+1; firstdt=ref_date; end; run;

proc transpose data=two out=three; by group firstdt; var ref_date; run;

proc sort data=one; by visit id; run;

data four; merge one three (rename=(firstdt=visit)); by visit; run;

proc transpose data=four out=five (drop=_name_ where=(^missing(ref_date))); by id notsorted; var col:; run;

data five; set five; by id notsorted; if first.id then grp=1; else grp=0; run;

proc print; format ref_date ddmmyy10.; run;

ID Ref_date gr

19 31/07/2000 1 19 24/07/2000 0 19 17/07/2000 0 19 10/07/2000 0 19 03/07/2000 0 41 02/08/2000 1 41 09/08/2000 0 41 16/08/2000 0 41 23/08/2000 0 41 30/08/2000 0 52 02/08/2000 1 52 09/08/2000 0 52 16/08/2000 0 52 23/08/2000 0 52 30/08/2000 0 19 14/08/2000 1 19 07/08/2000 0 19 21/08/2000 0 19 28/08/2000 0

On Wed, 5 Sep 2007 20:42:07 -0000, olana98@GOOGLEMAIL.COM wrote:

>Dear SAS Group, > >I wanted to merge two data sets. One contains patient information- >date of hospital visit and others. Commonly, there are several daily >visits leading to multiple observations in a day. The second data set >contains an exposure parameter measured on the day of visit and >several controls spaced weeks apart. The plan is to merge each >hospital visit to several exposure dates. I have copied a sample data >set. The ID is not unique in the data set as a patient may visit a >hospital more than once. It appears it is many to many merging and I >attempt with ordinary merging did not produce the required result.Any >suggestion is appreciated. Thanks and best wishes > >Data set one >ID Visit >19 31/07/2000 >41 02/08/2000 >52 02/08/2000 >19 14/08/2000 > >Data set two > >Ref_date Grp What I wanted to achieve > >31/07/2000 1 19 31/07/2000 1 >24/07/2000 0 19 24/07/2000 0 >17/07/2000 0 19 17/07/2000 0 >10/07/2000 0 19 10/07/2000 0 >03/07/2000 0 19 03/07/2000 0 >02/08/2000 1 41 02/08/2000 1 >09/08/2000 0 41 09/08/2000 0 >16/08/2000 0 41 16/08/2000 0 >23/08/2000 0 41 23/08/2000 0 >30/08/2000 0 41 30/08/2000 0 >14/08/2000 1 52 02/08/2000 1 >07/08/2000 0 52 09/08/2000 0 >21/08/2000 0 52 16/08/2000 0 >28/08/2000 0 52 23/08/2000 0 > 52 30/08/2000 0 > 19 14/08/2000 1 > 19 07/08/2000 0 > 19 21/08/2000 0 > 19 28/08/2000 0


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