Sample 24658: Using the MODIFY statement with the KEY= option
Update an indexed data set in place using the KEY= option to
locate the matching observations.
Note:
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.
/*****************************************************************************/
/* An index is created for data set STORE (master) using the INDEX= data set */
/* option for the key variable ITEM. */
/* */
/* An observation is read from the GROCERY_LIST (transaction) data set and */
/* a matching observation in STORE is located using the index. The */
/* automatic variable _IORC_ is tested using the mnemonics defined in the */
/* SAS-supplied %SYSRC autocall macro. */
/* */
/* The value _SOK means there was a match found in the master data set, */
/* and the value _DSENOM means a match was not found. */
/*****************************************************************************/
data store(index=(Item));
input Item $ Inventory Aisle $;
datalines;
Milk 15 A
Soymilk 8 A
Eggs 24 A
Cheese 14 A
Bread 12 D
Muffins 8 D
;
data Grocery_List;
input Item $ Quantity;
datalines;
Bread 2
Milk 1
Butter 1
;
data Store;
/* Value of KEY variable comes from transaction data set */
set Grocery_List;
/* Index used to find matches for KEY= value */
modify store key=Item;
/* Check return code from search */
select (_iorc_);
when (%sysrc(_sok)) do;
/* Match found */
inventory=Inventory - quantity;
replace;
end;
when (%sysrc(_dsenom)) do;
/* Match not found in master */
_ERROR_=0;
put "Item not in stock --- " Item;
end;
otherwise do;
put 'Unexpected ERROR: _iorc_= ' _iorc_;
stop;
end;
end;
run;
proc print data=store;
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 Inventory Aisle
1 Milk 14 A
2 Soymilk 8 A
3 Eggs 24 A
4 Cheese 14 A
5 Bread 10 D
6 Muffins 8 D
Update an indexed data set in place using the KEY= option to
locate the matching observations.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> MODIFY SAS Reference ==> Statements ==> File-handling ==> MODIFY ==> with KEY= Common Programming Tasks ==> Combining Data
|
| Date Modified: | 2008-01-25 14:35:00 |
| Date Created: | 2004-09-30 14:09:01 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |