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 (February 1997, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 21 Feb 1997 06:13:05 -0600
Reply-To:     Tom Kalfas <kalfast@PPRD.ABBOTT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Tom Kalfas <kalfast@PPRD.ABBOTT.COM>
Subject:      Re: Last(Frist).var when two variables are used in the BY
              statement
Comments: To: Wayne Yu <wyu@GPU4.SRV.UALBERTA.CA>
In-Reply-To:  Wayne Yu <wyu@GPU4.SRV.UALBERTA.CA> "Last(Frist).var when two
              variables are used in the BY statement" (Feb 15, 11:33pm)
Content-Type: text/plain; charset=us-ascii

Wayne,

The answer was 1 test run away. You simply sort the dataset by the variables CITY and YEAR, and then in a subsequent datastep keep the LAST.CITY to keep the CITY records with the greatest YEAR value:

proc sort data=<whatever> out=<whatever>; by CITY YEAR; run;

data <whatever>; set <whatever>; by CITY YEAR; if LAST.CITY; run;

Tom

On Feb 15, 11:33pm, Wayne Yu wrote: > Subject: Last(Frist).var when two variables are used in the BY statement > Hello all, > > I have sorted a file by City and Year and let's say it looks like > > Denver 1990 13.5 > Denver 1991 14.5 > Denver 1992 14.8 > LA 1979 9.8 > LA 1980 10.9 > LA 1981 -10.6 > NY 1982 19.8 > NY 1983 9.8 > ... > > I want to pick out each city's last year's observation. So the resultant > sample will look like > > Denver 1992 14.8 > LA 1981 -10.6 > ... > I know one can use the temporary variable created by SAS 'last.variable' > to pick out the last observation for cases where there is only one sorting > variable. The question is how can I do this with two sorting variables? > > Your help is greatly appreciated. Please send your help reply to > wyu@gpu.srv.ualberta.ca > > Thanks in advance! > > Wayne >-- End of excerpt from Wayne Yu

-- Thomas Kalfas System Developer Abbott Laboratories

E-mail: kalfast@pprd.abbott.com

Phone: (847) 938-8101 Fax: (847) 935-1320


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