Chapter Contents |
Previous |
Next |
NAMEDITEM |
Category: | List |
Syntax | |
Details | |
Example | |
See Also |
Syntax |
index=NAMEDITEM(list-id,name<,occurrence
<,start-index<,forceup>>>); |
Type: Numeric
Type: Numeric or List
Type: Character
Type: Numeric
Type: Numeric
'Y' |
specifies a case-insensitive search, which overrides the HONORCASE or NOHONORCASE list attribute. |
'N' |
specifies a search that uses the HONORCASE or NOHONORCASE list attribute and is the default action for lists when FORCEUP is not specified. |
IGNORECASE | is an alias for NOHONORCASE. |
Details |
NAMEDITEM searches only the top level of the list specified by list-id. That is, it does not search sublists. Several functions that access items in a list by position have counterparts that access items by their names such as GETITEMC versus GETNITEMC. Because it is more efficient to retrieve an item by its position rather than by its name, you can use NAMEDITEM to find the position and then use the functions that access items by position rather than by name.
If occurrence and start-index are both positive or both negative, the search proceeds forward from the start-index item. For forward searches, the search continues only to the end of the list and does not wrap back to the front of the list. If occurrence or start-index is negative, the search is backwards. For backward searches, the search continues only to the beginning of the list and does not wrap back to the end of the list.
Example |
Swap the numeric values associated with the first and
last occurrence of the item named
x
:
/* Return first occurrence of X. */ first=getnitemn(listid,'X'); /* Return last occurrence of X. */ last=getnitemn(listid,'X',1,-1); list=setnitemn(listid,last,'X'); list=setnitemn(listid,first,'X',1 -1);
The following example shows a slightly more efficient
way to perform the swap operation. This method does not require a second search
for the item, and it can also detect when item
x
does not exist in the list.
/* Return the position number of the */ /* first item X. */ ifirst=nameditem(listid,'X'); if (ifirst>0) then do; first=getitemn(listid,ifirst); /* Return the position of the last item X.*/ ilast=nameditem(listid,'X',1,-1); list=setitemn(listid,getitemn(listid,ilast), ifirst); list=setitemn(listid,first,ilast); end;
Note: This example checks to see whether
there is at least one item named
x
but never checks to see whether there is another item named
x
. It assumes that there is at
least one more item named
X
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.