Sample 24748: Overwriting a master data set with duplicate transactions
Update a master data set in place using values supplied by a look-up data set.
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.
/* Create sample data sets */
data veggies(index=(item));
input Item $ Inventory ;
datalines;
Corn 12
Lettuce 6
Potato 15
Onion 7
;
data new_inventory;
input Item $ Quantity;
datalines;
Lettuce 2
Onion 7
Lettuce 3
;
/* There is no automatic update of like named variables with KEY=. */
/* */
/* To overwrite the values of INVENTORY in the master data set with */
/* all matches in the look-up data set, use an assignment statement. */
data veggies;
set new_inventory;
modify veggies key=Item/unique;
select (_iorc_);
when (%sysrc(_sok)) do;
inventory=quantity;
replace;
end;
when (%sysrc(_dsenom)) do;
_ERROR_=0;
inventory=.;
put "Item not in stock --- " Item;
end;
otherwise do;
put 'Unexpected ERROR: _iorc_= ' _iorc_;
stop;
end;
end;
run;
proc print data=veggies;
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
1 Corn 12
2 Lettuce 3
3 Potato 15
4 Onion 7
Update a master data set in place using values supplied by
a look-up data set.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> MODIFY Common Programming Tasks ==> Combining Data SAS Reference ==> Statements ==> File-handling ==> MODIFY ==> with KEY=
|
| Date Modified: | 2008-01-25 14:38:53 |
| Date Created: | 2004-09-30 14:09:10 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |