48 %MACRO assertLibrary (
 
   51    ,i_desc         = Bibliotheken prüfen
 
   52    ,i_libraryCheck = STRICT
 
   53    ,i_CompareCheck = STRICT
 
   56    ,i_ExcludeList  = _NONE_
 
   60    %IF &g_inTestcase EQ 1 %THEN %DO;
 
   63    %ELSE %IF &g_inTestcase NE 2 %THEN %DO;
 
   64       %PUT &g_error: assert must be called after initTestcase;
 
   68    %LOCAL l_casid l_tstid;
 
   70        i_type     = assertLibrary
 
   71       ,i_expected = %eval (%sysfunc (libref (&i_expected.))=0)
 
   72       ,i_actual   = %eval (%sysfunc (libref (&i_actual.))=0)
 
   79    %local l_actual_ok l_expected_ok l_result l_path_actual l_path_expected _sysinfo l_col_names l_id_col l_counter l_id;
 
   81    %*************************************************************;
 
   82    %*** Check preconditions                                   ***;
 
   83    %*************************************************************;
 
   85    %*** check 
for valid actual libref ***;
 
   86    %let l_actual_ok=%sysfunc (libref (&i_actual.));
 
   87    %
if (&l_actual_ok. > 0) %then %
do;
 
   88        %put &g_error: Libref i_actual (&i_actual.) is invalid!;
 
   93    %*** check for valid expected libref ***;
 
   94    %let l_expected_ok=%sysfunc (libref (&i_expected.));
 
   95    %if (&l_expected_ok. > 0) %then %do;
 
   96        %put &g_error: Libref i_expected (&i_expected.) is invalid!;
 
  101    %*** check for equal librefs ***;
 
  102    %if (&i_actual. = &i_expected.) %then  %do;
 
  103        %put &g_error: Librefs are identical!;
 
  108    %*** check for identical paths ***;
 
  109    %let l_path_actual = %sysfunc (pathname (&i_actual.));
 
  110    %let l_path_expected = %sysfunc (pathname (&i_expected.));
 
  111    %if ("&l_path_actual."  = "&l_path_expected.") %then %do;
 
  112        %put &g_error: paths are identical!;
 
  117    %let i_LibraryCheck = %upcase (%trim(&i_LibraryCheck.));
 
  118    %if (&i_LibraryCheck. ne STRICT AND &i_LibraryCheck. ne MORETABLES) %then %do;
 
  119        %put &g_error: Value of i_LibraryCheck (%trim(&i_LibraryCheck.)) is invalid!;
 
  124    %let i_CompareCheck = %upcase (%trim(&i_CompareCheck.));
 
  125    %if (&i_CompareCheck. ne STRICT AND &i_CompareCheck. ne MORECOLUMNS 
 
  126         AND &i_CompareCheck. ne MOREOBS AND &i_CompareCheck. ne MORECOLSNOBS) %then %do;
 
  127        %put &g_error: Value of i_CompareCheck (%trim(&i_CompareCheck.)) is invalid!;
 
  132    %let i_ExcludeList = %upcase (%trim(&i_ExcludeList.));
 
  136    %*************************************************************;
 
  137    %*** start tests                                           ***;
 
  138    %*************************************************************;
 
  140    %*** get table names from the two libraries ***;
 
  142       create table WORK._assertLibraryActual as
 
  143          select libname as BaseLibname,
 
  144                 memname as BaseMemName,
 
  145                 nlobs as BaseObs format=commax18.,
 
  146                 nvar as BaseNVar format=commax18.
 
  147          from dictionary.tables
 
  148          where libname = "%upcase(&i_actual)" 
 
  149             %if (&i_ExcludeList. ne _NONE_) %then %do;
 
  152                %let l_id_col = %scan (&i_ExcludeList.,&counter., %str ( ));
 
  153                %do %while (&l_id_col. ne );
 
  155                   %let counter=%eval (&counter.+1);
 
  156                   %let l_id_col = %scan (&i_ExcludeList.,&counter., %str ( ));
 
  161       create table WORK._assertLibraryExpected as
 
  162          select libname as CmpLibname,
 
  163                 memname as CmpMemName,
 
  164                 nlobs as CmpObs format=commax18.,
 
  165                 nvar as CmpNVar format=commax18.
 
  166          from dictionary.tables
 
  167          where libname = "%upcase(&i_expected)"
 
  168             %if (&i_ExcludeList. ne _NONE_) %then %do;
 
  171                %let l_id_col = %scan (&i_ExcludeList.,&counter., %str ( ));
 
  172                %do %while (&l_id_col. ne );
 
  174                   %let counter=%eval (&counter.+1);
 
  175                   %let l_id_col = %scan (&i_ExcludeList.,&counter., %str ( ));
 
  182    %*** flag tables according to check results ***;
 
  184       length DoCompare CompareFailed l_rc 8;
 
  185       merge WORK._assertLibraryActual (in=InAct rename=(BaseMemname=memname))
 
  186             WORK._assertLibraryExpected (in=InExp rename=(CmpMemname=memname));
 
  191       if (InAct AND inExp) then do;
 
  194          if (BaseObs ne CmpObs) then do;
 
  195             if ("&i_CompareCheck." = "STRICT" OR "&i_CompareCheck." = "MORECOLUMNS") then do;
 
  199          if (BaseNVar ne CmpNVar) then do;
 
  200             if ("&i_CompareCheck." = "STRICT" OR "&i_CompareCheck." = "MOREOBS") then do;
 
  205       else if (InAct AND not inExp AND "&i_LibraryCheck." ne "STRICT") then do;
 
  215    %*** determine number of compared tables ***;
 
  217       select sum (DoCompare) into :AnzCompares
 
  221    %if (&AnzCompares. > 0) %then %do;
 
  222       %do i=1 %to &AnzCompares.;
 
  227          select memname into :Memname1-:Memname%trim(&AnzCompares.)
 
  232       %*** upcase for 
id columns ***;
 
  233       %if (&i_id. ne _NONE_) %then %do;
 
  234          %let i_id=%upcase (&i_id.);
 
  237       %*** Check for open ODS DESTINATIONS ***;
 
  238       %local OpenODSDestinations;
 
  239       %let   OpenODSDestinations=0;
 
  241       %*** SASHELP.VDEST is only available in 9.2 or later ***;
 
  242       %if (&sysver. NE 9.1) %then %do; 
 
  244             select count (*) into :OpenODSDestinations from sashelp.vdest;
 
  248       %if (&OpenODSDestinations. = 0) %then %do;
 
  252       %*** Compare each pair of tables ***;
 
  253       %do i=1 %to &AnzCompares.;
 
  254          %if (&i_id. ne _NONE_) %then %do;
 
  258                select distinct upcase (name) into :l_col_names separated by ' '
 
  259                from dictionary.columns
 
  260                where libname = "%upcase (&i_actual.)" AND upcase (memname) = "%upcase(&&memname&i.)";
 
  264             %let l_id_col = %scan (&i_id.,&counter., %str ( ));
 
  265             %do %while (&l_id_col. ne );
 
  266                 %let l_found=%sysfunc (indexw (&l_col_names, &l_id_col.));
 
  267                 %if (&l_found. > 0) %then %do;
 
  268                    %let l_id = &l_id. &l_id_col;
 
  270                %let counter=%eval (&counter.+1);
 
  271                %let l_id_col = %scan (&i_id.,&counter., %str ( ));
 
  276             base=&i_expected..&&memname&i. 
 
  277             compare=&i_actual..&&memname&i.
 
  278             %if (&i_fuzz. ne _NONE_) %then %do;
 
  282             %if (&i_id. ne _NONE_) %then %do;
 
  286          %let _sysinfo=&sysinfo.;
 
  288             update work._ergebnis
 
  290             where upcase (memname)="%upcase (&&memname&i.)";
 
  295    %if (&OpenODSDestinations. = 0) %then %do;
 
  299    %*** set test result ***;
 
  306             if ("&i_CompareCheck." = "MOREOBS" OR "&i_CompareCheck." = "MORECOLSNOBS") then do;
 
  311             if ("&i_CompareCheck." = "MORECOLUMNS" OR "&i_CompareCheck." = "MORECOLSNOBS") then do;
 
  316             if ("&i_CompareCheck." = "MORECOLSNOBS") then do;
 
  324    %*** format results for report ***;
 
  326       length icon_column $45 i_LibraryCheck i_CompareCheck $15 i_id i_ExcludeList $80;
 
  328       SELECT (CompareFailed);
 
  329          WHEN (0) icon_column='<img src="ok.png" alt="OK"></img>';
 
  330          WHEN (1) icon_column='<img src="error.png" alt="Fehler"></img>';
 
  331          OTHERWISE icon_column=' ';
 
  333       i_LibraryCheck="&i_LibraryCheck.";
 
  334       i_CompareCheck="&i_CompareCheck.";
 
  336       i_ExcludeList="&i_ExcludeList.";
 
  339    %*** determine return value for test ***;
 
  341       select max (CompareFailed) into :l_rc
 
  345    %*** create library listing ***;
 
  346    ods document name=testout._%substr(00&g_scnid,%length(&g_scnid))_&l_casid._&l_tstid._Library_act(WRITE);
 
  347       proc print data=WORK._assertLibraryActual label noobs;
 
  350    ods document name=testout._%substr(00&g_scnid,%length(&g_scnid))_&l_casid._&l_tstid._Library_exp(WRITE);
 
  351       proc print data=WORK._assertLibraryExpected label noobs;
 
  354    data testout._%substr(00&g_scnid,%length(&g_scnid))_&l_casid._&l_tstid._Library_rep;
 
  358    proc datasets lib=work nolist memtype=(data view);
 
  359       delete _ergebnis _assertLibraryActual _assertLibraryExpected;
 
  368             tst_scnid = &g_scnid AND
 
  369             tst_casid = &l_casid AND