Sample 24783: Updating when data sets contain duplicates
Overlay values in master data set with non-missing
values from a second data set.
Note:
Update uses observations from the transaction data
set to change the values of the corresponding
observations from the master data set. You must
use a BY statement. Data needs to be in sorted
order, or indexed.
Update works with two data sets only.
Note that if the master data set contains
duplicates of the BY variable, the first
observation is updated and the remaining
observations are ignored.
If the transaction data set contains duplicates,
all values overlay the first match in master.
If your goal is to update all the observations
in master, consider using MERGE instead.
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 pretend data. DSD assumes the delimiter is a comma */
/* and strips the double quotes from the values with embedded */
/* delimiters. */
/* */
/* A WARNING will be issued to the log due to the duplicates */
/* found in master. */
/**************************************************************/
data one;
infile datalines dsd;
input artist $ song :$30.;
datalines;
Abba,"Knowing Me, Knowing You"
Abba,I am the City
Abba,Mama Mia
Beatles,Blackbird
Beatles,Chains
Beatles,"Ob-La-Di, Ob-La-Da"
;
data two;
infile datalines dsd;
input artist $ song :$30. new;
datalines;
Abba,Waterloo,1
Beatles,Glad All Over,1
Beatles,Hey Jude,1
Doors,People Are Strange,1
;
data new;
update one two;
by artist;
run;
proc print data=new;
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 artist song new
1 Abba Waterloo 1
2 Abba I am the City .
3 Abba Mama Mia .
4 Beatles Hey Jude 1
5 Beatles Chains .
6 Beatles Ob-La-Di, Ob-La-Da .
7 Doors People Are Strange 1
Overlay values in master data set with non-missing
values from a second data set.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> UPDATE Common Programming Tasks ==> Combining Data Data Management ==> Manipulation and Transformation ==> Combining and Modifying Data Sets
|
| Date Modified: | 2005-12-08 11:34:34 |
| Date Created: | 2004-09-30 14:09:13 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |