You can interrogate the views in SASHELP (vtable, vcolumn etc) to do this. A quick way would be to create a temporary table from sashelp.vcolumn for each of the two tables you want to compare, then use a PROC SQL join to compare them. Then you'll be comparing the structures, which is represented in the data from vcolumn.
To get started with this, have a look at what's in SASHELP.vcolumn.
Here is a basic example of employing this method, to compare variables in 2 datasets.
* 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 generalise from this for other attributes such as data type, length, label etc., all of which are available in vcolumn.
- Note that you may need to alter this code to accommodate librefs that your data sets may have.