Sample 25216: Updating values in one SAS table with values from another SAS table
It's important to note that the second WHERE clause prevents
rows in table ONE from being updated with missing values,
if the value for ONE.COL1 does not have a matching value in
TWO.COL1.
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 one;
input col1 col2 $;
cards;
1 test1
2 test2
3 test3
4 test4
5 test5
6 test6
7 test7
8 test8
9 test9
10 test10
;
data two;
input col1 col2 $;
cards;
1 UPDATED1
3 UPDATED3
5 UPDATED5
7 UPDATED7
9 UPDATED9
;
proc sql ;
update one
set col2 = (select two.col2 from two
where one.col1=two.col1)
where one.col1 in (select col1 from two);
quit;
proc print data=one;
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 col1 col2
1 1 UPDATED1
2 2 test2
3 3 UPDATED3
4 4 test4
5 5 UPDATED5
6 6 test6
7 7 UPDATED7
8 8 test8
9 9 UPDATED9
10 10 test10
This example illustrates updating the values of ONE.COL2 with the values from TWO.COL2, providing there is a match between COL1 in both tables.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> SQL
|
Date Modified: | 2005-03-19 03:02:45 |
Date Created: | 2005-02-14 10:29:44 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |