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 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 1 Sep 2004 16:13:12 -0400
Reply-To:     Nathaniel_Wooding@DOM.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Nat Wooding <Nathaniel_Wooding@DOM.COM>
Subject:      Re: selecting id that have multiple records
Comments: To: Mayukh Dass <dass@UGA.EDU>
Content-type: text/plain; charset=US-ASCII

Mayukh

The following solution should work for you

data a; input id; cards; A ..... B ... B B C C D D D E F G H H data b;set a; by id; 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.

Nat Wooding

Mayukh Dass <dass@UGA.EDU> To: SAS-L@LISTSERV.UGA.EDU Sent by: "SAS(r) cc: Discussion" Subject: selecting id that have multiple records <SAS-L@LISTSERV.U GA.EDU>

09/01/04 03:29 PM Please respond to Mayukh Dass

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


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