Chapter Contents

Previous

Next
SEARCHC, SEARCHL, SEARCHN, and SEARCHO

SEARCHC, SEARCHL, SEARCHN, and SEARCHO



Search for a value in an SCL list and return its position number

Category: List


Syntax
Details
Examples
Example 1: Using the SEARCHC Function
Example 2: Using the SEARCHL Function
Example 3: Using the SEARCHN Function
Example 4: Using the SEARCHO Function
See Also

Syntax

index=SEARCHC(list-id,cval<,start-index
<,occurrence<,ignore-case<,prefix>>>>);
index=SEARCHL(list-id,sublist-id<,occurrence
<,start-index>>);
index=SEARCHNlist-id,nval(<,occurrence
<,start-index>>);
index=SEARCHO(list-id,object-id<,occurrence
<,start-index>>);

index
contains the index from the SCL list of the item that has the specified character value, or 0 if the value was not found.

Type: Numeric

list-id
is the identifier of the list to search. An invalid list-id produces an error condition.

Type: Numeric or List

cval
is the character value for SEARCHC to search for. Cval is compared only to the character values in the list.

Type: Character

sublist-id
contains the identifier of the sublist for SEARCHL to search for. Sublist-id is compared only to the list identifiers in the list.

Type: Numeric

nval
is the numeric value for SEARCHN to search for. Nval is compared only to numeric values in the list.

Type: Numeric

object-id
contains the identifier of the object for SEARCHO to search for. Object-id is compared only to the object identifiers in the list.

Type: Numeric or Object

occurrence
is the occurrence of the value to search for. The default, 1, indicates the first occurrence of the item.

Type: Numeric

start-index
is the position in the list at which to start the search for the item. By default, start-index is 1 (the first item). If start-index is positive, then the search begins at position start-index items from the beginning of the list. If start-index is negative, then the search 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

ignore-case
specifies how SEARCHC should compare string values:
'Y' ignores the case of the character strings.
'N' does a case-sensitive comparison of the character strings. (This is the default.)

Type: Character

prefix
specifies whether the value should be treated as a prefix:
'Y' does a prefix comparison and searches for any items that have cval as a prefix. SEARCHC compares only the first m characters, where m is the length of cval.
'N' does not do a prefix search but compares all characters to cval. (This is the default.)

Type: Character


Details

SEARCHC, SEARCHL, SEARCHN, and SEARCHO do not search for a value in any sublists of the list identified by list-id.

If occurrence and start-index are both positive or both negative, then 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 either occurrence or start-index is negative, then the search proceeds from the last item toward the beginning of the list. For backward searches, the search continues only to the beginning of the list and does not wrap back to the end of the list.

To search for an item by name rather than by value, use NAMEDITEM.


Examples

Example 1: Using the SEARCHC Function

Find the position of the next-to-last occurrence of a string that begins with SAS, ignoring case:

last2=searchc(mylistid,'sas',2,-1,'Y','Y');

Example 2: Using the SEARCHL Function

Search the list identified by MYLISTID for the third occurrence of the identifier for the sublist item identified by the value of NAMELISTID:

third=searchl(mylistid,namelistid,3);

Example 3: Using the SEARCHN Function

Search for the third occurrence of the number 46 in the list identified by MYLISTID:

third=searchn(mylistid,46,3);

Example 4: Using the SEARCHO Function

Search the list identified by MYLISTID for the third occurrence of the identifier for the object BUTTON:

third=searcho(mylistid,objectid,3);

See Also

NAMEDITEM


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.