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 (March 1999, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 25 Mar 1999 14:23:54 -0500
Reply-To:   HERMANS1 <HERMANS1@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   HERMANS1 <HERMANS1@WESTAT.COM>
Subject:   Re: Sorting BY functions/expressions
Comments:   To: John Whittington <medisci@POWERNET.COM>
Content-Type:   text/plain; charset=US-ASCII

Offhand I'd say that the SAS System already has the capability that you want (even if it does require use of the SQL procedure that some may consider unaesthetic). You can specify a physical ordering of the observations in the dataset by either creating an ordered view of a dataset in SQL and SETting the view in a data step, or by defining the output of a datastep as a view (say, Xvw, and sorting the dataset in a SQL statement (say, ....SELECT * FROM Xvw ORDER BY UCASE(var), LENGTH(var), ABS(numvar). For those inclined to data step programming can regard these methods as special SORT procedures that sort on functions of variables. Sig

____________________Reply Separator____________________ Subject: Sorting BY functions/expressions Author: John Whittington <medisci@POWERNET.COM> Date: 3/25/99 3:29 PM

A week or two ago, Ian Whitlock suggested an 'inventive sort', using SQL, for a situation in which a 'standard sort' (PROC SORT) could not give the desired sort order unless one created new variables. The relevant extract of Ian's code is:

> proc sql ; > select .... > order by substr(memname,1,6) , > year (mdy(1,1, input(substr(memname,7,2),2.)))

This led me to think how useful it could be if PROC SORT was able to sort 'BY' functions of variables (and maybe also variable expressions), rather than just 'whole' variables. In addition to substr(), one can imagine many situations in which it would be very useful to be able to sort 'BY', for example, UCASE(var), LENGTH(var), ABS(numvar) etc. etc. At the very least, it would avoid the need to create new variables just for the sake of the sort.

What do people think?

Regards,

John

---------------------------------------------------------------- Dr John Whittington, Voice: +44 (0) 1296 730225 Mediscience Services Fax: +44 (0) 1296 738893 Twyford Manor, Twyford, E-mail: medisci@powernet.com Buckingham MK18 4EL, UK mediscience@compuserve.com ----------------------------------------------------------------


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