Date: Tue, 1 Feb 2011 13:51:48 -0500
Reply-To: vivian v <v.vivian3@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: vivian v <v.vivian3@GMAIL.COM>
Subject: Re: match merge data without overwriting
In-Reply-To: <201102011737.p11GMtrw029791@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
Thanks so much for your detailed explaination. Now I understand. Really
learn a lot from it. Thanks!
On Tue, Feb 1, 2011 at 12:37 PM, Arthur Tabachneck <art297@rogers.com>wrote:
> Vivien,
>
> All my code did was combine the two files into one:
>
> >> data want;
> >> set one two;
> >> run;
>
> Sort that file by id:
> >> proc sort data=want;
> >> by id;
> >> run;
>
> And then, in a datastep, use a by statement so that the two variables
> first.id and last.id could be analyzed (they are automatically created
> when
> you include a by statement). Their values are equal 1 if true, 0 if false.
> Thus, if an id only had one record (i.e., only came from one of the files),
> then both variables would have the value 1. The only time the statement:
> if
> not(first.id and last.id); could be true is when an id had more than one
> record.
>
> >> data want;
> >> set want;
> >> by id;
> >> if not(first.id and last.id);
> >> run;
>
> Art
> -------
> On Tue, 1 Feb 2011 12:27:11 -0500, vivian v <v.vivian3@GMAIL.COM> wrote:
>
> >Hi, Arthur,
> >It works very well. But I still don't understand how it works, like the
> last
> >data step. Can you explain a little bit to me? Thank you so much!
> >
> >Best,
> >
> >On Tue, Feb 1, 2011 at 12:14 PM, Arthur Tabachneck
> <art297@rogers.com>wrote:
> >
> >> Vivian,
> >>
> >> Since you don't have duplicate records for any ids within either file,
> >> aren't you just trying to something like?:
> >>
> >> data one;
> >> input id x;
> >> cards;
> >> 1 1
> >> 2 2
> >> 3 1
> >> 4 2
> >> ;
> >>
> >> data two;
> >> input id x;
> >> cards;
> >> 1 1
> >> 2 2
> >> 4 2
> >> ;
> >>
> >> data want;
> >> set one two;
> >> run;
> >>
> >> proc sort data=want;
> >> by id;
> >> run;
> >>
> >> data want;
> >> set want;
> >> by id;
> >> if not(first.id and last.id);
> >> run;
> >>
> >> Art
> >> --------
> >> On Tue, 1 Feb 2011 11:48:15 -0500, vivian v <v.vivian3@GMAIL.COM>
> wrote:
> >>
> >> >I also want to exclude the un-matched records.
> >> >Can this work in this case?
> >> >Thanks!
> >> >
> >> >
> >> >
> >> >On Tue, Feb 1, 2011 at 11:44 AM, Gerhard Hellriegel <
> >> >gerhard.hellriegel@t-online.de> wrote:
> >> >
> >> >> use set instead of merge.
> >> >>
> >> >> Gerhard
> >> >>
> >> >>
> >> >>
> >> >> On Tue, 1 Feb 2011 11:37:00 -0500, vivian v <v.vivian3@GMAIL.COM>
> >> wrote:
> >> >>
> >> >> >Hi, all,
> >> >> >I have question about the match- merging data. I have two datasets.
> >> Both
> >> >> of
> >> >> >them have the exactly the same variables. I only want the record
> with
> >> the
> >> >> >same id names in both of the datasets.
> >> >> >Those two records (with the same id names) have different
> information.
> >> I
> >> >> >want to keep both of the records. I wrote the merge data code as
> >> follows:
> >> >> >*
> >> >> >
> >> >> >data* new;
> >> >> >
> >> >> >merge old1(in=inpt)
> >> >> >
> >> >> >old2(in=inid);
> >> >> >
> >> >> >by ptid;
> >> >> >
> >> >> >if inpt and inid;
> >> >> >
> >> >> >*run*;
> >> >> >
> >> >> >But the result showed that there is only one record for every ptid.
> How
> >> >> can
> >> >> >I keep both the records? Thanks very much for your attention.
> >> >>
> >>
>
|