Date: Fri, 7 Jul 2006 15:32:03 -0400
Reply-To: Joe Whitehurst <joewhitehurst@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Whitehurst <joewhitehurst@GMAIL.COM>
Subject: Re: Macros written on a boring Friday
In-Reply-To: <BAY101-F179E360F50D3177EC7BEE9DE740@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Toby,
Great examples for illustrating the clear superiority of SCL over AML. I
will not bother replicating your first example because it would look just
like your code with the macro baggage removed since you have basically used
SCL functions. Your second example, however, reduces to just one line of
code for the sort, 1 line to define the initial list and two lines to send
the before and after list to the log:
init:
dcl list MyList={3, 5, 6, 4, 1, 2};
call putlist(mylist,'Unsorted List:',5);
rc=sortlist(mylist);
call putlist(mylist,'Sorted List:',5);
return;
The log:
Unsorted List:( 3
5
6
4
1
2
)[5]
Sorted List:( 1
2
3
4
5
6
)[5]
Wait, there is much more. The SORTLIST function has many options to control
the sort:
SAS Component Language Dictionary
SORTLIST
------------------------------
Sorts the items in an SCL list by value or by name Category: List
------------------------------
Syntax<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000146354.htm#a002648167>
Details<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000146354.htm#a000320407>
Examples<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000146354.htm#a000320408>
See
Also<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000146354.htm#a000317674>
------------------------------
Syntax rc=SORTLIST(list-id<,options<,start-index<,n-items>>>);
rc
contains the identifier of the sorted list. The value passed as list-id is
returned unless there is an error. The value 0 means out of memory.
Type: Numeric
list-id
is the identifier of the list to sort. An invalid list-id produces an error
condition.
Type: Numeric or List
options
specify how the sort operation is performed. Multiple options can be
specified, separated by blanks. Each option can be abbreviated to a unique
substring. The substring can be as short as the first character for all
options except 'NAME' and 'NODUP', which may be abbreviated to two
characters, 'NA' or 'NO', respectively. Later keywords override previous
keywords.
'ASCENDING'
Sort the list in ascending order. (This is a default.)
'DESCENDING'
Sort the list in descending order.
'IGNORECASE'
Ignore case when comparing string values. Case is always ignored when
sorting by name, because names are always converted to uppercase.
'NAME'
Sort the list by item name. Unnamed items appear before named items in an
ascending sort.
'NODUP'
Delete duplicate items when sorting. All but the first item in the sort
range that have the same value (or the same name, if sorting by name) are
deleted. The default is not to delete duplicates.
'OBEYCASE'
Obey case when comparing string values. This is the default when sorting by
value.
'VALUE'
Sort the list by item value. In an ascending sort, character items precede
list identifiers, which precede numeric missing values, followed by
non-missing numeric values. (This is a default.)
Type: Character
start-index
specifies the starting position for sorting a range of items in the list. By
default, start-index is 1 (the first item). If start-index is positive, then
the range begins start-index items from the beginning of the list. If
start-index is negative, then the range begins at the item specified by ABS(
start-index) items from the end of the list. An error condition results if
the absolute value of start-index is zero or if it is greater than the
number of items in the list.
Type: Numeric
n-items
specifies the number of items in the list to sort. The default is all items
between start-index and the opposite end of the list. To explicitly specify
all items, specify -1.
Type: Numeric
------------------------------
Details
SORTLIST does not make a copy of the list before it is sorted. The list is
modified in place.
Sublists that are contained in the sorted list are not sorted recursively.
When you specify the 'NODUP' and 'IGNORECASE' options, the character list
items or names that are spelled the same but differ only in case are
considered duplicates, and all but the first occurrence are removed from the
sorted list.
An error occurs if the list has the NOUPDATE attribute or if an item to be
removed has the NODELETE attribute, if NODUP is specified. Use HASATTR to
check the attributes of a list or item. To change attributes, use SETLATTR.
------------------------------
Examples
-
Sort the first 10 items in a list in descending order:
list=sortlist(list,'D',1,10);
-
Sort the last 16 items in a list in ascending order:
list=sortlist(list,'',-1,16);
-
Sort the second ten items in a list in ascending name order, deleting
items that have duplicate names:
list=sortlist(list,'NODUP ASCENDING NAME',11,10);
------------------------------
See Also
HASATTR<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000143507.htm>
REVLIST<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000146352.htm>
ROTLIST<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000146353.htm>
SETLATTR<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000143508.htm>
[image: space] [image: space] Previous
Page<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000320400.htm>
| Next Page<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000144167.htm>
| Top of Page<http://support.sas.com/onlinedoc/913/getDoc/en/sclref.hlp/a000146354.htm#a000146354>
Copyright 2003 by SAS Institute Inc., Cary, NC, USA. All rights
reserved.<http://support.sas.com/onlinedoc/913/getDoc/en/common.hlp/images/copyrite.htm>