LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (April 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 21 Apr 2009 11:53:10 -0700
Reply-To:     "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Subject:      Re: Keeping Unique Obs
In-Reply-To:  A<16FD64291482A34F995D2AF14A5C932C07437C76@MAIL002.prod.ds.russell.com>
Content-Type: text/plain; charset="us-ascii"

sdlentertd -

An optional point - you can avoid the DESCENDING sort option by using the LAST.Member_ID flag rather than FIRST.Member_ID...

data have; input Member_ID city $ state $ date mmddyy10.; cards; 0123 boston ma 04/05/2009 0123 newyork ny 01/09/2009 0123 boston ma 01/09/2009 0456 boston ma 01/09/2009 0456 boston ma 06/09/2009 ; run;

proc sort; BY Member_ID date; run;

DATA want; SET have; BY Member_ID date; IF LAST.Member_ID; run;

Paul Choate DDS Data Extraction (916) 654-2160

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Terjeson, Mark Sent: Tuesday, April 21, 2009 11:41 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Keeping Unique Obs

Hi,

The short answer is: change IF FIRST.date; to IF FIRST.Member_ID;

data have; input Member_ID city $ state $ date mmddyy10.; cards; 0123 boston ma 04/05/2009 0123 newyork ny 01/09/2009 0123 boston ma 01/09/2009 0456 boston ma 01/09/2009 0456 boston ma 06/09/2009 ; run;

proc sort; BY Member_ID DESCENDING date; run;

DATA want; SET have; BY Member_ID DESCENDING date; put _all_; IF FIRST.Member_ID; run;

The long answer is that if you were to add put _all_; between your BY and IF statement in your datastep you would see the 1/0 flags for all the combinations of the BY statement variables. It would be noticable by you that indeed you do want to sort each member group with descending date, however, if you use first.date you will find a TRUE(1) for every date value since that IS the first occurance of each date value. So what you really are after is (and is still dependent upon the sort BY mbr and descending date) you want only the first record for each mbr group. You could have sorted the date ascending and then grabbed the last.Member_ID. Either direction would yield you the largest date per each mbr.

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst Investment Management & Research Russell Investments 253-439-2367

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of sdlentertd@GMAIL.COM Sent: Tuesday, April 21, 2009 11:24 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Keeping Unique Obs

NEED HELP WITH FIGURING OUT HOW TO KEEP FISR OBS.

I have:

Member_ID city state date 0123 boston ma 04/05/2009 0123 new york ny 01/09/2009 0123 boston ma 01/09/2009 0456 boston ma 01/09/2009 0456 boston ma 06/09/2009

Need to have 0123 boston ma 04/05/2009 0456 boston ma 06/09/2009

I am running this code DATA want; SET have; BY Member_ID DESCENDING date; IF FIRST.date; run;

So for Member 0456 it only gives me the correct info but for 0123 i get 0123 boston ma 04/05/2009 0123 new york ny 01/09/2009

It's not just looking at Member_ID duplicates but it makes sure that the whole line is not dup... But I Only need Unique Member_ID's info with the latest date... So one line per Member ID.. Thank you


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