Date: Wed, 1 Sep 2004 12:44:16 -0700
Reply-To: "Terjeson, Mark" <TERJEM@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <TERJEM@DSHS.WA.GOV>
Subject: Re: selecting id that have multiple records
Content-Type: text/plain
Hi Roy,
One of several approaches is the datastep
and the FIRST. LAST. flags which get built
when the BY statement is used with the SET
statement. I use this frequently for grabbing
the singles or the multiples, just like here
where you want to keep the multiples and throw
away the singles.
data sample;
infile cards pad;
input ID $ price region;
cards;
A . .
B . .
B . .
B . .
C . .
C . .
D . .
D . .
D . .
E . .
F . .
G . .
H . .
H . .
;
run;
data result;
set sample;
by id;
if first.id and last.id then delete;
run;
Hope this is helpful,
Mark Terjeson
Reporting, Analysis, and Procurement Section
Information Services Division
Department of Social and Health Services
State of Washington
mailto:terjem@dshs.wa.gov
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Mayukh Dass
Sent: Wednesday, September 01, 2004 12:29 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: selecting id that have multiple records
Hi,
I have a dataset with variables ID, price, region and so on. It looks
like the following:
ID price region
A .....
B ...
B
B
C
C
D
D
D
E
F
G
H
H
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 H 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 1.
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,
Mayukh
|