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 (October 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 6 Oct 2008 13:32:59 -0400
Reply-To:     Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:      Re: how to select the first value from a repeated dataset
Comments: To: "jn_mao@yahoo.com" <jn_mao@yahoo.com>
In-Reply-To:  <781201.10460.qm@web32706.mail.mud.yahoo.com>
Content-Type: text/plain; charset="us-ascii"

Jane: proc sort data= .... out= .... nodupkey; by id var1; run;

will give you an arbitrary selection of the first record in physical order per BY group in the original data. I'd do this carefully to make sure that you will obtain what you want. For example, you may have to run initially a regular sort procedure "BY id var1 var2;" to make sure that the first obs in each group has the smallest value of var2.

In general it would be better to have distinct key including a sequencing attribute in each obs to prevent having to rely on physical ordering of a dataset. Reordering a dataset will change its physical order and could generate a different result should you have to replicate or repeat the process. S

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of jn mao Sent: Monday, October 06, 2008 1:00 PM To: SAS-L@LISTSERV.UGA.EDU Subject: how to select the first value from a repeated dataset

Hello SAS-Ls,

I have a longitudinal data set. Now I want to only select the first value of 3 from var1, how do I write the SAS code? Some ids have repeated 3, but I only want to output the first 3 and other variable values.

My original data: id var1 var2 1 3 11 1 3 12 1 5 13 2 2 5 2 3 7 2 3 8 2 4 11 3 2 6 3 3 9

The data I want: id var1 var2 1 3 11 2 3 7 3 3 9

Can someone help me out this? Thanks much.

Jane


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