|
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
----------------------------------------------------------------
|