You can poll views in SASHELP (vtable, vcolumn, etc.) to do this. A quick way is to create a temporary table from sashelp.vcolumn for each of the two tables you want to compare, and then use the PROC SQL join to compare them. Then you will compare the structures that are represented in the data from vcolumn.
To start with this, look at SASHELP.vcolumn.
Here is a basic example of using this method to compare variables in two data sets.
* provide names of the two data sets here ;
%let ds1=TheFirstDataSet;
%let ds2=TheOtherDataSet;
* upcase the data set names ;
%let ds1=%sysfunc(upcase(&ds1));
%let ds2=%sysfunc(upcase(&ds2));
proc sql;
* retrieve info on these tables from sashelp.vcolumn;
create table first as select * from sashelp.vcolumn where upcase(memname)="&ds1";
create table second as select * from sashelp.vcolumn where upcase(memname)="&ds2";
* join these data sets and report on differences for var names;
select coalescec(f.name,s.name) as varName
,case
when f.name is null then "This var is in &ds2 only"
when s.name is null then "This var is in &ds1 only"
else 'This var is in both data sets'
end as DiffDescription
from
first as f
full outer join
second as s
on f.name=s.name
;
quit;
You can generalize this to other attributes, such as data type, length, label, etc., all of which are available in vcolumn.
- Note that you may need to modify this code to accommodate the librefs that your datasets may have.
source
share