By default, performing a left join on two tables results in a table that contains all the observations from the left table, along with the matching observations from the right table based on a common variable. The reverse is true when performing a right join on two tables. Often, however, you want your results to contain only the non-matching observations in one of the two tables. This sample explains how to retrieve only the non-matching rows from a join, and create an output table that contains only those rows.
This sample was created using SAS Enterprise Guide 4.2.
Following is code that you can use to create the data sets used in this sample. You can run these DATA steps in a SAS Enterprise Guide code node. To open a code node, select File ► New ► Program. The goal of this sample is to return all of the observations in the BASE table that are not in the RECORDS table, based on the common variable PATIENT.
data base;
input patient $ drug $ date: date9.;
format date date9.;
cards;
a a 1jan2005
b b 1feb2005
c c 1mar2005
d d 1mar2005
e e 1apr2005
f f 1may2005
g g 1jun2005
h h 1jun2005
;
run;
|
Figure 1. DATA step code for the BASE table
data records;
input patient $ drug2 $ date2: date9.;
format date date9.;
cards;
a p 1aug2007
b q 1nov2007
d t 1oct2007
e v 1nov2007
g x 1dec2007
;
run;
|
Figure 2. DATA step code for the RECORDS table
For illustration purposes, this sample uses a LEFT join.
This is what the join should look like. The join is based on the common variable PATIENT.
This is what the filter should look like:
For more information about using SAS Enterprise Guide, see the SAS Enterprise Guide documentation page.
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.
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.
Type: | Sample |
Date Modified: | 2010-09-08 15:54:00 |
Date Created: | 2010-07-21 15:57:09 |
Product Family | Product | Host | Product Release | SAS Release | ||
Starting | Ending | Starting | Ending | |||
SAS System | SAS Enterprise Guide | Windows Vista for x64 | 4.2 | 9.2 TS2M0 | ||
Windows Vista | 4.2 | 9.2 TS2M0 | ||||
Microsoft Windows XP Professional | 4.2 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2008 for x64 | 4.2 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 for x64 | 4.2 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Standard Edition | 4.2 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Enterprise Edition | 4.2 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Datacenter Edition | 4.2 | 9.2 TS2M0 | ||||
Microsoft® Windows® for x64 | 4.2 | 9.2 TS2M0 |