2010-09-29 52 views
3

我是一個測試人員,我需要比較SAS中的兩個數據集結構(不是表數據)。 我試圖使用'proc比較',但它比較數據。我想比較數據集/表結構(列名,數據類型,空限制等)如何比較SAS中的表結構

任何人都可以幫忙嗎?

回答

6

您可以詢問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; 

您可以從中概括其他屬性,如數據類型,長度,標籤等,所有這些屬性都可在vcolumn中找到。

  • 請注意,您可能需要更改此代碼以適應您的數據集可能具有的librefs。
3

您可以使用proc contents將描述符部分寫入數據集,然後使用proc compare來查看它們的結構如何不同。 out2選項將寫出完整性約束條件(如果存在)。如果不是,數據集將是空的。像CRDATE(創建日期)或LIBNAME或MEMNAME等一些列可能會有所不同,因此您可能希望將這些列從比較中排除。

/* create some fake data similar to an existing one */ 
proc sql; 
create table myclass as 
    select *, "foo" as newcol from sashelp.class 
; 
/* modify it */ 
    insert into myclass 
    values ("George", "M", 17, 72, 169,"foo"); 
/* add an index */ 
    create index names on 
    work.myclass(name, age); 
quit; 

/* write out descriptor portions to data sets */ 
proc contents data=myclass out=ds1 out2=ds2;run; 
/* sashelp.class doesn't have an index so ds2a will not exist */ 
proc contents data=sashelp.class out=ds1a out2=ds2a;run; 

/* compare data set structures */ 
proc compare data=ds1 compare=ds1a;run; 
1

1-使用PROC內容,讓您的數據集的描述(數據集名,變量名,變量標籤,變量類型....)

2- PROC SORT的所有內容輸出的

3-使用PROC COMPARE。

***********************************************; 
proc content data=table1 out=cont1 noprint; 
run; 

proc content data=table2 out=cont2 noprint; 
run; 

proc sort data=cont1; 
    by memname name; 
run; 

proc sort data=cont2; 
    by memname name; 
run; 

proc compare listvar 
    base=cont1 
    compare=cont2; 
    id memname name; 
run; 
******************* END ************;