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 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sat, 6 Sep 2008 16:09:31 -0400
Reply-To:   "Howard Schreier <hs AT dc-sug DOT org>" <schreier.junk.mail@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Howard Schreier <hs AT dc-sug DOT org>" <schreier.junk.mail@GMAIL.COM>
Subject:   Re: Keep the last observation only. How?

On Sat, 6 Sep 2008 12:48:19 -0400, Nat Wooding <Nathaniel.Wooding@DOM.COM> wrote:

>Ferda > >You will find that usually SAS offers more than one or two solutions to a >problem. The following uses data step programming to do what you want. > >Data start; >INFORMAT fundid 8. Date YYMMDD6. value 8.; >input FundID Date Value; >format date mmddyy10.; >CARDS; > 1 88-08-29 0.6665 > 1 88-08-31 0.6476 > 1 88-09-30 0.6257 > 1 88-10-31 0.6243 > 1 88-11-14 0.6216 > 1 88-11-21 0.6204 > 1 88-11-28 0.5999 > 1 88-12-31 0.55 > 3 96-02-19 0.8364 > 3 96-02-29 0.8364 > 3 96-03-15 0.8198 > 3 96-03-29 0.8198 > 3 96-04-15 0.8289 > 3 96-04-30 0.8289 >PROC PRINT; >RUN; > >data wanted; > set start; > year = year(date);*these statements could have been put in the >previous step; > month = month(date); >run; > >Data Wanted; > set wanted; > by fundid year month; > if last.month ; >run; > >Nat Wooding >Environmental Specialist III >Dominion, Environmental Biology >4111 Castlewood Rd >Richmond, VA 23234 >Phone:804-271-5313, Fax: 804-271-2977

Here's a one-step variation:

data wanted; set start; by fundid date groupformat; if last.date; format date monyy.; run;

> > > > help4SASnewbie > <shopaholic777@GM > AIL.COM> To > Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU > Discussion" cc > <SAS-L@LISTSERV.U > GA.EDU> Subject > Keep the last observation only. > How? > 09/06/2008 10:40 > AM > > > Please respond to > help4SASnewbie > <shopaholic777@GM > AIL.COM> > > > > > > >Hi, I need to keep the last the last end-month value for each FundID. >As seen on Table1, some months has 2 or more values, for example Year >88 Month 08 has 0.6665 and 0.6476. >The value to keep is the end-month only. >Please see table 2 to illustrate desired output. > >Table 1: Input > FundID Date Value > 1 88-08-29 0.6665 > 1 88-08-31 0.6476 > 1 88-09-30 0.6257 > 1 88-10-31 0.6243 > 1 88-11-14 0.6216 > 1 88-11-21 0.6204 > 1 88-11-28 0.5999 > 1 88-12-31 0.55 > 3 96-02-19 0.8364 > 3 96-02-29 0.8364 > 3 96-03-15 0.8198 > 3 96-03-29 0.8198 > 3 96-04-15 0.8289 > 3 96-04-30 0.8289 > >Table 2: Desired Output > FundID Date >Value > 1 88-08-31 0.6476 > 1 88-09-30 0.6257 > 1 88-10-31 >0.6243 > 1 88-11-28 0.5999 > 1 88-12-31 >0.55 > 3 96-02-29 >0.8364 > 3 96-03-29 >0.8198 > 3 96-04-30 0.8289 > >It will be great if you could help with the code to solve this. >Many thanks in advance! >Ferda - a SAS newbie >


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