Sample 38059: Determining variables that data sets have in common
In order to determine the variables that are in common to multiple data sets, first create an output data set using PROC CONTENTS and keep the NAME variable. Then simply MERGE all the data sets using NAME on a BY statement.
Example:
data one;
input x y z;
cards;
1 2 3
;
run;
data two;
input x a y;
cards;
1 1 1
;
run;
data three;
x=1;
run;
proc contents data=one noprint out=out1(keep=name);
run;
proc contents data=two noprint out=out2(keep=name);
run;
proc contents data=three noprint out=out3(keep=name);
run;
data common_vars;
merge out1(in=a) out2(in=b) out3(in=c);
by name;
if a and b and c then output;
run;
proc print;
run;
This method can also be used to determine common variable values across data sets.
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.
When working with multiple data sets, it may be useful to find out what variables are in common. PROC COMPARE will only give you the number of variables that are in common but not the names, and PROC COMPARE can only evaluate two data sets at a time. This method uses DATA step logic.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step
|
Date Modified: | 2010-01-20 09:37:35 |
Date Created: | 2009-12-07 11:54:11 |
Operating System and Release Information
SAS System | Base SAS | z/OS | | |
OpenVMS VAX | | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
Microsoft Windows XP 64-bit Edition | | |
Microsoft® Windows® for x64 | | |
OS/2 | | |
Microsoft Windows 7 | | |
Microsoft Windows 95/98 | | |
Microsoft Windows 2000 Advanced Server | | |
Microsoft Windows 2000 Datacenter Server | | |
Microsoft Windows 2000 Server | | |
Microsoft Windows 2000 Professional | | |
Microsoft Windows NT Workstation | | |
Microsoft Windows Server 2003 Datacenter Edition | | |
Microsoft Windows Server 2003 Enterprise Edition | | |
Microsoft Windows Server 2003 Standard Edition | | |
Microsoft Windows Server 2008 | | |
Microsoft Windows XP Professional | | |
Windows Millennium Edition (Me) | | |
Windows Vista | | |
64-bit Enabled AIX | | |
64-bit Enabled HP-UX | | |
64-bit Enabled Solaris | | |
ABI+ for Intel Architecture | | |
AIX | | |
HP-UX | | |
HP-UX IPF | | |
IRIX | | |
Linux | | |
Linux for x64 | | |
Linux on Itanium | | |
OpenVMS Alpha | | |
OpenVMS on HP Integrity | | |
Solaris | | |
Solaris for x64 | | |
Tru64 UNIX | | |