Sample 24624: Using KEY= with duplicate key values in lookup data set
Use the KEY= option to locate observations in an indexed data set
based upon values from another data set containing duplicates.
Note:
Execution of the SET statement with the KEY= option forces a
search to begin at the top of the index only when the value of
the KEY= variable changes in the lookup data set between fetch
operations. If duplicate values for the key variable exist
consecutively in the lookup data set, the value does not change
between executions. Therefore, to force the search to begin at
the top, use the UNIQUE option. With non-consecutive duplicate
values, the search begins at the top of the index structure.
If a DROP or KEEP is not specified, using the KEY= option
combines all variables on the lookup data set and the primary
data set.
When using KEY= it's necessary to test the automatic variable
_IORC_.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data catalog(index=(item_no));
input item_no item $ price;
datalines;
111 scarf 50
222 gloves 39
333 mittens 48
444 coat 92
555 sled 29
777 goggle 31
888 vest 49
999 socks 12
;
data order;
input item_no;
datalines;
111
111
222
888
;
data summary;
set order end=last;
set catalog key= item_no/unique;
length filled $12.;
select (_iorc_);
/* Match condition */
when (%sysrc(_sok)) do;
total + price ;
filled='yes';
output;
end;
/* Non-match condition */
when (%sysrc(_dsenom)) do;
_ERROR_=0;
filled='invalid item';
output;
end;
otherwise do;
put 'Unexpected ERROR: _iorc_= ' _iorc_;
stop;
end;
end;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs item_no item price filled total
1 111 scarf 50 yes 50
2 111 scarf 50 yes 100
3 222 gloves 39 yes 139
4 888 vest 49 yes 188
Use the KEY= option to locate observations in an indexed data set
based upon values from another data set containing duplicates.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> SET ==> with KEY= SAS Reference ==> Statements ==> File-handling ==> SET Data Management ==> Manipulation and Transformation ==> Combining and Modifying Data Sets
|
| Date Modified: | 2005-12-08 11:34:12 |
| Date Created: | 2004-09-30 14:08:59 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |