|Data Set Model: _setKey|
|CALL SEND (object-id, '_setKey', rc<, keyname><, condition><, scroll><, val-list>);|
||N||returns whether the key was successfully applied|
|0||key was successfully applied|
||C||specifies the name of the key or index to use on the table. The keyname may specify a single or a composite index.|
||C||specifies the condition to use when comparing the key value:|
|'GE'||greater than or equal to|
|'LE'||less than or equal to|
||C||specifies whether rows can be retrieved in random order:|
|'SCROLL'||rows can be retrieved in random order (default)|
|'NOSCROLL'||rows can only be retrieved sequentially|
||N||specifies the identifier of an SCL list that contains values to use in the key. The item name should reflect the appropriate column name, and the item value should be the value that the key value is compared against.|
If you modify the current row in the table, you must use the _updateRow method before calling the _setKey method.
The _setKey method enables you to set an active key in an open table to a simple or composite key. It establishes a set of criteria for reading table rows by evaluating the value of the columns against the key value in the rows.
Using a composite key with _setKey operates the same way as the _where method only when the condition is EQ. The value returned when the condition is EQ is the same as if the columns specified in the composite key were connected by WHERE conditions that use AND or ALSO.
For all other conditions (GT, GE, LT, or LE) specified with _setKey
for a composite key, the composite key columns are concatenated together to
form the index key. The number returned by the _keyCount method is the number
of rows in the table that satisfy the composite key. For example, if the
composite index consists of columns SEX and AGE and the condition is GT (greater
than), the values to search for are concatenated such that key values of
F for SEX and 13 for AGE yield an index key of
Because the search is performed on the concatenated values, some values may
meet the search condition that you did not expect, such as SEX of
and AGE of 11, because the string
M11 is considered greater
than the string
Once an active key is set through the _setKey method, it remains active until the following conditions are met:
The table is automatically positioned at the row that meets the specified criteria. Use the _getRow or _fetchRow method to read the row.
The _setKey method cannot be used in conjunction with a WHERE clause.
The _setKey method sets SYSRC for error, note, and warning conditions.
In the following example, the Data Set Model class is being used as a stand-alone model, that is, the model class is not being used with a data form or data table object.
This example creates an index on the STATE variable in the table SASUSER.CRIME. It subsets on STATE values less than 20. In this example, COUNT returns 15.
INIT: dsid=open('sasuser.crime', 'v'); rc=icreate(dsid, 'state', 'state'); dsid=close(dsid); datcl=loadclass('sashelp.fsp.datast_m.class'); datid=instance(datcl);
call send(datid,'_setDataset', 'sasuser.crime');
list=makelist(); list=setnitemn(list, 20, 'state'); call send(datid, '_setKey', rc, 'state', 'LT', 'scroll', list); call send(datid, '_keyCount', rc, count); put count=; return;
TERM: call send(datid,'_term'); list=dellist(list); return;
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.