Sample 24786: Updating a master data set containing duplicates with all matching duplicates from a look-up data set
Update a master data set in place using values supplied by
a second data set when both tables contain duplicates for
the key value.
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.
/***********************************************************************/
/* There is no automatic update of like named variables with KEY=. */
/* If the goal is to accumulate the values of INVENTORY instead of */
/* overwriting them, an accumulation statement is needed. */
/* */
/* The automatic variable _IORC_ is tested using the mnemonics defined */
/* in the SAS-supplied %SYSRC autocall macro. The value _SOK means a */
/* match was found, and the value _DSENOM means a match was not found. */
/***********************************************************************/
data master (index=(x));
input x y;
datalines;
1 2
1 3
2 4
3 5
5 2
;
data trans;
input x y;
datalines;
1 8
1 2
3 9
5 2
;
data master;
set trans(rename=(y=y2));
by x;
dummy=0;
do until (_IORC_=%sysrc(_dsenom));
if dummy then x=.;
modify master key=x;
select (_iorc_);
when (%sysrc(_sok)) do;
y=y + y2;
replace;
end;
when (%sysrc(_dsenom)) do;
_ERROR_=0;
if not last.x and not dummy then do;
dummy=1;
_IORC_=0;
end;
end;
otherwise ;
end;
end;
run;
proc print data=master;
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 x y
1 1 12
2 1 13
3 2 4
4 3 14
5 5 4
Update a master data set in place using values supplied by
a second data set when both tables contain duplicates for
the key value.
| 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:39:15 |
| Date Created: | 2004-09-30 14:09:14 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |