Date: Wed, 1 Sep 2004 16:13:12 -0400
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel_Wooding@DOM.COM>
Subject: Re: selecting id that have multiple records
Content-type: text/plain; charset=US-ASCII
The following solution should work for you
data b;set a;
if first.id + last.id = 2 then delete;
First.id and last.id are automatic variables that are created when one
includes a by statement as above. First.id =1 for the first record in a
group; otherwise it is 0. Likewise, last.id is 1 for the last record in the
set and otherwise 0. Hence, if you add the two together, the sum will be 2
only for unique records.
<dass@UGA.EDU> To: SAS-L@LISTSERV.UGA.EDU
Sent by: "SAS(r) cc:
Discussion" Subject: selecting id that have multiple records
09/01/04 03:29 PM
Please respond to
I have a dataset with variables ID, price, region and so on. It looks like
ID price region
And so on.
I am trying to select the records whose ID has more than one record. For
example, my new dataset should contain all the records of ID = B, C, D and
of the above sample dataset.
I have done the task in a round about way where I first found the frequency
of ID and then selected the records whose ID has a frequency of more than
I was wondering whether there is any shortcut way of doing this. SAS has a
lot of one-word functions like lag, first and so on. By shortcut, I meant
whether any one-word function exist to do this job.
Thanks in advance,