sac*_*hin 3 compare sas data-structures
我是测试人员,我需要比较SAS中的两个数据集结构(不是表数据).我尝试使用'proc compare'但它会比较数据.我想比较数据集/表结构(列名,数据类型,空约束等)
任何人都可以帮忙吗?
您可以在SASHELP(vtable,vcolumn等)中查询视图来执行此操作.一种快速的方法是从sashelp.vcolumn为要比较的两个表中的每一个表创建一个临时表,然后使用PROC SQL连接来比较它们.然后,您将比较结构,这些结构在vcolumn的数据中表示.
要开始使用它,请查看SASHELP.vcolumn中的内容.
以下是使用此方法比较2个数据集中的变量的基本示例.
* 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;
Run Code Online (Sandbox Code Playgroud)
您可以从中推广其他属性,例如数据类型,长度,标签等,所有这些属性都可以在vcolumn中使用.