Chapter Contents |
Previous |
Next |
GETNITEMC, GETNITEML, GETNITEMN, and GETNITEMO |
Category: | List |
Syntax |
cval=GETNITEMC(list-id,name<,occurrence <,start-index<,default<,force>>>>); |
sublist-id=GETNITEML(list-id,name<,occurrence <,start-index<,default<,force>>>>); |
nval=GETNITEMN(list-id,name<,occurrence <,start-index<,default<,force>>>>); |
obj-val=GETNITEMO(list-id,name<,occurrence <,start-index<,default<,force>>>>); |
Type: Character
Type: List
'Y'
or if the searched
list has the attribute NOHONORCASE set. Trailing blanks are ignored when the
list is searched for a matching name. Thus, the names 'abc' and 'Abc' are
converted to 'ABC'.
IGNORECASE is the alias for NOHONORCASE and is the default for a list. But you can use the SETLATTR function to set a list's attribute to HONORCASE.
Type: Character
Type: Numeric or List
Type: Numeric
Type: List
Type: Numeric
Type: Object
'N' |
searches according to the list attributes HONORCASE and NOHONORCASE, which are specified with SETLATTR. (This is the default.) |
'Y' |
conducts the name search in uppercase regardless of list attributes specified with SETLATTR. |
Type: Character
Details |
By default, the search starts at the beginning of the list and returns the first item found that has the specified item name. However, you can start the search at a different place in the list by specifying a start-index other than 1. You can also specify a different occurrence of the item (for example, the second, tenth, or twentieth) by specifying an occurrence other than 1. If the item is not found and you have specified a value for default as the fifth parameter, then that value is returned instead of an error condition.
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, then 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.
GETNITEMC combines the actions of NAMEDITEM and GETITEMC. GETNITEML combines the actions of NAMEDITEM and GETITEML. GETNITEMN combines the actions of NAMEDITEM and GETITEMN. GETNITEMO combines the actions of NAMEDITEM and GETITEMO.
In situations where your application manipulates an SCL list and you cannot guarantee that the named item is character, you should not use GETNITEMC. Instead, when manipulating SCL lists which may contain other types, you should use NAMEDITEM with ITEMTYPE with GETITEMC, GETITEML, GETITEMN, or GETITEMO.
An error condition results if
Examples |
Halt the program if there are fewer than two items named 'Software Sales'
in
the list identified by DIRECTORY. Omitting
the default value from GETNITEMC designates that the character item must exist
in the list.
s=getnitemc(directory,'Software Sales',2,-1);
This statement is equivalent to the following statements:
ssi=nameditem(directory,'Software Sales',2,-1); s=getitemc(directory,ssi);
Both of the preceding examples search for the second
occurrence of 'Software Sales'
, starting from
the end of the list.
This example shows how to search for a named item in an SCL list when you do not know the type of that item.
index = nameditem(listid, 'A', occurrence, startIndex); if index then select (itemtype(listid, index)); when ('C') c = getitemc(listid, index); when ('L') l = getiteml(listid, index); when ('N') n = getitemn(listid, index); when ('O') o = getitemo(listid, index); end;
If the named item may not be in the list, supply a list identifier value for default for GETNITEML:
sslistid=getniteml (emp_list,'Marketing',2,-10,-1);
The preceding program statement is equivalent to the following:
mpos=nameditem(emp_list,'Marketing',2,-10); if mpos ne 0 then sslistid=getiteml(emp_list,mpos); else sslistid=-1;
This example shows GETNITEMC, using a default value that contains an error message.
defaultc='Value not found'; s=getnitemc (directory,'Software Sales',2,-1,defaultc);
See Also |
GETITEMC, GETITEML, GETITEMN, and GETITEMO
SEARCHC, SEARCHL, SEARCHN, and SEARCHO
SETNITEMC, SETNITEML, SETNITEMN, and SETNITEMO
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.