/*-------------------------------------------------------------- * * SAS TEST LIBRARY * * NAME: migrate_macros.sas * TITLE: contains macros which produce validatation output * for MIGRATE * SUPPORT: David Wiehle david.wiehle@sas.com * INPUT: see below * OUTPUT: migrate_macros.log * migrate_macros.lst * SPEC.REQ: see below *--------------------------------------------------------------*/ *--------------------------------------------------------------* * This program was designed to be used in conjunction with a * data migration template program (migrate_template.sas). * Please refer to this data migration template program to * determine the order in which the macros defined below should * be run. In order for the macros contained in this program to * work, the following must be true: * * 1. The source library containing files to be migrated must be * assigned to libref "lib1". * 2. The target library must be assigned to libref "lib2". * 3. A separate library must be assigned to a libref named "ods". * This is the destintation for data sets created with the ODS * output statements below. *--------------------------------------------------------------*; *--------------------------------------------------------------* * mig_in_lib produces an ODS output data set which contains * the members and memtypes in a library. These data sets * must be created before any of the macros below can be * successfully run. * * To output the contents of the source library before the * MIGRATE: %mig_in_lib(lib=lib1) * * To output the contents of the source library after the * MIGRATE: %mig_in_lib(lib=lib1, after=y) * * To output the contents of the target library after the * MIGRATE: %mig_in_lib(lib=lib2) * *--------------------------------------------------------------*; %macro mig_in_lib(lib, after); %let suffix=m; %if &after ne %then %do; %if &lib=lib1 %then %do; %let suffix=m_after; %end; %end; *--------------------------------------------------------------* * determine contents of library *--------------------------------------------------------------*; ods output members=ods.&lib.&suffix(drop=num filesize lastmodified); ods listing close; proc contents data=&lib.._all_;run; ods listing; *-------------------------------------------------------------------------* * change "name" variable for Generation data sets to a format recognized * by the EXIST function *-------------------------------------------------------------------------*; data ods.&lib.&suffix; length name $21.; set ods.&lib.&suffix; if GenNum gt 0 then do; name=compress(name||"#"||put(gennum, Z3.)); end; run; proc sort data=ods.&lib.&suffix;by memtype name;run; %mend mig_in_lib; *--------------------------------------------------------------* * mig_source produces memtype flag variables and creates macro * variables which contain the names of sas files in the source * library. *--------------------------------------------------------------*; %macro mig_source; %global audit_here catalog_here data_here index_here itemstore_here mddb_here program_here view_here lib1taudit lib1tcatalog lib1tdata lib1tindex lib1titemstore lib1tmddb lib1tprogram lib1tview ; *-------------------------------------------------------------------------------* * Create memtype "flag" variables. Initialize them to null. *-------------------------------------------------------------------------------*; %let audit_here=; %let catalog_here=; %let data_here=; %let index_here=; %let itemstore_here=; %let mddb_here=; %let program_here=; %let view_here=; *-------------------------------------------------------------------------------* * Create memtype counter variables. Initialize them to zero. *-------------------------------------------------------------------------------*; data _null_; call symput("lib1taudit", put(0,8.)); call symput("lib1tcatalog", put(0,8.)); call symput("lib1tdata", put(0,8.)); call symput("lib1tindex", put(0,8.)); call symput("lib1titemstore", put(0,8.)); call symput("lib1tmddb", put(0,8.)); call symput("lib1tprogram", put(0,8.)); call symput("lib1tview", put(0,8.)); run; data _null_; set ods.lib1m end=eof; by memtype name; *-------------------------------------------------------------------------------* * initialize a "memtype counter variable" to zero. *-------------------------------------------------------------------------------*; retain n 0; if first.memtype then do; *-------------------------------------------------------------------------------* * Set the values of the memtype flag variables to "Y" if a member with that * memtype exists in the source library. *-------------------------------------------------------------------------------*; select (memtype); when ("AUDIT") do; call symput("audit_here","Y"); end; when ("CATALOG") do; call symput("catalog_here","Y"); end; when ("DATA") do; call symput("data_here","Y"); end; when ("INDEX") do; call symput("index_here","Y"); end; when ("ITEMSTOR") do; call symput("itemstore_here","Y");end; when ("MDDB") do; call symput("mddb_here","Y"); end; when ("PROGRAM") do; call symput("program_here","Y"); end; when ("VIEW") do; call symput("view_here","Y"); end; otherwise; end; *-------------------------------------------------------------------------------* * Set the memtype counter to one. *-------------------------------------------------------------------------------*; n=1; *-------------------------------------------------------------------------------* * combine the the memtype and the counter variable into a macro variable. Do * the same with the libref, memtype and member name. *-------------------------------------------------------------------------------*; call symput(compress("lib1mt"||put(n,8.)), memtype); call symput(compress("lib1"||memtype||put(n,8.)),name); *-------------------------------------------------------------------------------* * if this also happens to be the last memtype, output the counter variable into * a macro variable containing the total number of this particular memtype. *-------------------------------------------------------------------------------*; if last.memtype then do; call symput(compress("lib1t"||memtype),put(n,8.)); end; end; else if not first.memtype then do; n+1; if not last.memtype then do; call symput(compress("lib1mt"||put(n,8.)), memtype); call symput(compress("lib1"||memtype||put(n,8.)),name); end; else if last.memtype then do; call symput(compress("lib1mt"||put(n,8.)), memtype); call symput(compress("lib1"||memtype||put(n,8.)),name); call symput(compress("lib1t"||memtype),put(n,8.)); end; end; run; %mend mig_source; *----------------------------------------------------------------* * macro %mig_indexes * If there are any Indexes and/or Integrity Constraints in the source * library, this macro creates a data set in the ODS library describing * the Indexes and/or Integrity Constraints in the source or target * libraries. * * The default behavior of this macro is to run on the source library. * To run this macro on the target library, set lib="LIB2" (case * sensitive). * * Please note this macro must be run after mig_source is run * (it uses one of the memtype flag variables created by mig_source). *----------------------------------------------------------------*; %macro mig_indexes(lib); %global ics_here; *-------------------------------------------------------------------------------* * Only run this macro if indexes are present * in the source library *-------------------------------------------------------------------------------*; %if &index_here=Y %then %do; %if &lib= %then %let lib=lib1; ***LIB1; **run on source library by default; ***jgb edit from LIB1 to lib1 12/23/2004 7:18AM--; %if &lib=lib1 %then %let title=source; %else %if &lib=lib2 %then %let title=target; proc contents data=lib1._all_ out2=ods.indy noprint;run; *--------------------------------------------------------------------------------* * Use the "type" variable to determine whether or not any Integrity Constraints * exist in the source library. Create a memtype "flag" variable for integrity * constraints. *--------------------------------------------------------------------------------*; data _null_; set ods.indy end=eof; retain count 0; if type ne "Index" then do; count+1; end; if eof then do; if count eq 0 then do; call symput("ics_here", " "); end; else if count ne 0 then do; call symput("ics_here", "Y"); end; end; run; *-------------------------------------------------------------------------------* * Indexes *-------------------------------------------------------------------------------*; ods output indexes=ods.&lib._idx; ods listing close; proc contents data=&lib.._all_;run; ods listing; *---------------------------------------------------------------* * "member" contains the libref name. This will * cause an insignificant COMPARE difference. If the values in * this variable contains expected values, remove libref * so that only the member name remains. *---------------------------------------------------------------*; data ods.&lib._idx(drop=member); set ods.&lib._idx; if index(member, "&lib")=1 then membr=substr(member, 6); else membr=member; run; *---------------------------------------------------------------* * The remaining integrity constraint information is expected * to be the same in each library. *---------------------------------------------------------------*; *-------------------------------------------------------------------------------* * Integrity constraints *-------------------------------------------------------------------------------*; %if &ics_here=Y %then %do; ods output IntegrityConstraints=ods.&lib._ics; ods listing close; proc contents data=&lib.._all_;run; ods listing; *---------------------------------------------------------------* * "member" and "reference" contain the libref name. This will * cause an insignificant COMPARE difference. If the values in * these variables contain expected values, remove libref * so that only the member name remains. *---------------------------------------------------------------*; data ods.&lib._ics(drop=member reference); set ods.&lib._ics; if index(member, "&lib")=1 then membr=substr(member, 6); else membr=member; if index (reference, "&lib")=1 then ref=substr(reference, 6.); else ref=reference; run; *---------------------------------------------------------------* * The remaining integrity constraint information is expected * to be the same in each library. *---------------------------------------------------------------*; %end; %end; %mend mig_indexes; *--------------------------------------------------------------* * mig_check_libs outputs a side-by-side comparison of the * contents of source library before migrate against the * contents of the target library after migrate. *--------------------------------------------------------------*; %macro mig_check_libs; *--------------------------------------------------------------* * merge contents of source library before MIGRATE and contents * * of target library after MIGRATE. * *--------------------------------------------------------------*; data ods.final; length result $30.; merge ods.lib1m(in=in1) ods.lib2m(in=in2); by memtype name; if in1 and in2 then result="OK"; else if in1 and not in2 then result="not MIGRATED"; else if not in1 and in2 then result="not in source library"; run; title2 "contents of target library after MIGRATE (relative to source lib)"; proc print data=ods.final; var name memtype result; run; %mend mig_check_libs; *--------------------------------------------------------------* * mig_check_source outputs a side-by-side comparison of the * contents of source library before and after the migrate. The * default behavior is based upon the default behavior of * MIGRATE (i.e., files not deleted from source library after * migration). To output results of a MIGRATE with the move * option: * * %mig_check_source(move=yes); * *--------------------------------------------------------------*; %macro mig_check_source(move); %if &move= %then %do; *--------------------------------------------------------------* * merge contents of source library before and after MIGRATE. * *--------------------------------------------------------------*; data ods.source_lib; length result $50.; merge ods.lib1m(in=in1) ods.lib1m_after(in=in2); by memtype name; if in1 and in2 then result= "OK"; else if in1 and not in2 then result="member present in source library before MIGRATE, but not after MIGRATE"; else if not in1 and in2 then result="member added to source library after MIGRATE"; run; title2 "contents of source library before and after MIGRATE"; title3 "(OK indicates member was present in source lib before and after MIGRATE)"; %end; %else %if &move=yes %then %do; *--------------------------------------------------------------* * merge contents of source library after MIGRATE with contents * of target library after MIGRATE. *--------------------------------------------------------------*; data ods.source_lib; length result $50.; merge ods.lib1m_after(in=in1) ods.lib2m(in=in2); by memtype name; if in1 and in2 then result="PROBLEM: member was migrated but NOT moved"; else if in1 and not in2 then result="member added to source library after MIGRATE"; else if in2 and not in1 then result="OK (member was moved)"; run; title2 "contents of source library before and after MIGRATE with the move option"; title3 "(OK indicates member was migrated and was deleted from source lib after MIGRATE)"; %end; proc print data=ods.source_lib; var name memtype result; run; %mend mig_check_source; *----------------------------------------------------------------* * macro %before includes all the macros that must be run before * the MIGRATE to produce default validation output. *----------------------------------------------------------------*; %macro before; %mig_in_lib(lib=lib1); %mig_source; %*mig_indexes; /* ------------- commented out, jgb, 12/28/2004 9:15AM %put *-----------------------------------------------------------------------*; %put * If the LIB1, LIB2 and ODS libraries have been defined correctly, and ; %put * migrate_macros.sas has been complied in this SAS session, this ; %put * macro does the following: ; %put * ; %put * 1. Creates a data set in the ODS library containing information about ; %put * the members in the source library before the MIGRATE. ; %put * 2. Creates global macro (flag) variables for each memtype. ; %put * 3. Creates global macro variables containing the name of each member ; %put * in the source library before the MIGRATE. ; %put * 4. Creates a global macro variable which indicates whether or not ; %put * there are any Integrity Constraints in the source library before ; %put * the MIGRATE. ; %put * 5. If there are any Indexes and/or Integrity Constraints in the source ; %put * library, this macro creates a data set in the ODS library describing; %put * the Indexes and/or Integrity Constraints in the source library ; %put * before the MIGRATE. ; %put *-----------------------------------------------------------------------*; end commented out ----------------------------- */ %mend before; *----------------------------------------------------------------* * macro %after includes all the macros that must be run after * the MIGRATE to produce default validation output. *----------------------------------------------------------------*; %macro after; %mig_in_lib(lib=lib1, after=y); %mig_in_lib(lib=lib2); %*mig_indexes(lib=LIB2); ****must be upper case; %mig_check_libs; %mig_check_source; /* %put *-----------------------------------------------------------------------*; %put * This macro does the following: ; %put * ; %put * 1. Creates a data set in the ODS library containing information about ; %put * the members in the source library after the MIGRATE. ; %put * 2. Creates a data set in the ODS library containing information about ; %put * the members in the target library after the MIGRATE. ; %put * 3. If there are any Indexes and/or Integrity Constraints in the source ; %put * library, this macro creates a data set in the ODS library which ; %put * describes Indexes and/or Integrity Constraints in the target ; %put * library after the MIGRATE. ; %put * 4. Outputs a side-by-side comparison of the contents of the source lib ; %put * before the MIGRATE with the contents of the target lib after the ; %put * MIGRATE in the SAS Output window. ; %put * 5. Outputs a side-by-side comparison of the contents of the source lib ; %put * before the MIGRATE with the contents of the source lib after the ; %put * MIGRATE in the SAS Output window. ; %put *-----------------------------------------------------------------------*; */ %mend after; *----------------------------------------------------------------* * CHECKDATA outputs the following to the lst: * 1. side-by-side comparison of data set attributes * 2. side-by-side comparison of data set engine host information * 3. proc compare of data set contents * * The default behavior of CHECKDATA is to output only those data * set attributes and engine/host data which are different in the * source library and the target library. To output a * comparison of all data set attributes and engine/host data, * submit the following: * %checkdata(showall=yes); *----------------------------------------------------------------*; %macro checkdata(showall); %do i=1 %to &lib1tdata; %let ishere=%sysfunc(exist(lib2.&&lib1data&i)); %if &ishere=1 %then %do; * 1. "smart compare" of data set attributes; ods output attributes=ods.atr1(keep=label1 cvalue1 where=(label1 not in (" ", "Data Set Name"/*, "Created", "Last Modified"*/))) attributes=ods.atr2(keep=label2 cvalue2 where=(label2 ne " ")) EngineHost=ods.lib1_data_eng&i(keep=label1 cvalue1 where=(label1 not in ("File Name"))); ods listing close; %if %sysfunc(index(&&lib1data&i, #)) gt 0 %then %do; proc contents data=lib1.%str("&&lib1data&i")n;run; %end; %else %do; proc contents data=lib1.&&lib1data&i;run; %end; ods listing; data ods.atr1(rename=(label1=attribute cvalue1=source)); set ods.atr1; run; data ods.atr2(rename=(label2=attribute cvalue2=source)); set ods.atr2; run; data ods.lib1_data_atr&i; set ods.atr1 ods.atr2; run; proc sort data=ods.lib1_data_atr&i;by attribute;run; data ods.lib1_data_eng&i(rename=(label1=attribute cvalue1=source)); set ods.lib1_data_eng&i; run; proc sort data=ods.lib1_data_eng&i;by attribute;run; ods output attributes=ods.atr1(keep=label1 cvalue1 where=(label1 not in (" ", "Data Set Name"/*, "Created", "Last Modified"*/))) attributes=ods.atr2(keep=label2 cvalue2 where=(label2 ne " ")) EngineHost=ods.lib2_data_eng&i(keep=label1 cvalue1 where=(label1 not in ("File Name"))); ods listing close; %if %sysfunc(index(&&lib1data&i, #)) gt 0 %then %do; proc contents data=lib2.%str("&&lib1data&i")n;run; %end; %else %do; proc contents data=lib2.&&lib1data&i;run; %end; ods listing; data ods.atr1(rename=(label1=attribute cvalue1=target)); set ods.atr1; run; data ods.atr2(rename=(label2=attribute cvalue2=target)); set ods.atr2; run; data ods.lib2_data_atr&i; set ods.atr1 ods.atr2; run; proc sort data=ods.lib2_data_atr&i;by attribute;run; data ods.lib2_data_eng&i(rename=(label1=attribute cvalue1=target)); set ods.lib2_data_eng&i; run; proc sort data=ods.lib2_data_eng&i;by attribute;run; data ods.comp_data_atr&i; merge ods.lib1_data_atr&i(in=in1) ods.lib2_data_atr&i(in=in2); by attribute; if in1 or in2; run; data ods.comp_data_eng&i; merge ods.lib1_data_eng&i(in=in1) ods.lib2_data_eng&i(in=in2); by attribute; if in1 or in2; run; title2 "%sysfunc(left(%sysfunc(trim(&&lib1data&i))))"; title3 "Number &i of %sysfunc(compress(&&lib1tdata)) data sets in source library"; %if &showall=yes %then %do; proc print data=ods.comp_data_atr&i; title4 "Comparison of PROC CONTENTS header information"; title5 "Number 1 of 3 reports for this data set (from checkdata macro)"; var attribute source target; run; proc print data=ods.comp_data_eng&i; title4 "Comparison of PROC CONTENTS engine/host information"; title5 "Number 2 of 3 reports for this data set (from checkdata macro)"; var attribute source target; run; %end; %else %if &showall ne yes %then %do; data ods.comp_data_atr&i; set ods.comp_data_atr&i; if source ne target; run; proc print data=ods.comp_data_atr&i; title4 "Differences in PROC CONTENTS header information"; title5 "Note: all other header information was the same"; title6 "Number 1 of 3 reports for this data set (from checkdata macro)"; var attribute source target; run; data ods.comp_data_eng&i; set ods.comp_data_eng&i; if source ne target; run; proc print data=ods.comp_data_eng&i; title4 "Differences in PROC CONTENTS engine/host information"; title5 "Note: all other engine/host information was the same"; title6 "Number 2 of 3 reports for this data set (from checkdata macro)"; var attribute source target; run; %end; * 2. proc compare of data set data; title4 "PROC COMPARE of data"; title5 "Number 3 of 3 reports for this data set (from checkdata macro)"; title6; %if %sysfunc(index(&&lib1data&i, #)) gt 0 %then %do; proc compare data=lib1.%str("&&lib1data&i")n comp=lib2.%str("&&lib1data&i")n briefsummary listall; run; %end; %else %do; proc compare data=lib1.&&lib1data&i comp=lib2.&&lib1data&i briefsummary listall; run; %end; *clean up data sets created in the ODS library by this macro; proc datasets lib=ods nolist; delete atr1 atr2 lib1_data_eng&i lib1_data_atr&i lib2_data_eng&i lib2_data_atr&i comp_data_atr&i comp_data_eng&i ; quit; %end; %else %do; data ods.nothere; note="No validation will be performed"; run; title2 "&&lib1data&i"; title3 "Number &i of %sysfunc(compress(&&lib1tdata)) data sets in source library"; title4 "Member is present in LIB1 but was not MIGRATED to LIB2"; proc print data=ods.nothere noobs;run; %end; %end; title2; title3; title4; title5; title6; %mend checkdata; *----------------------------------------------------------------* * CHECKAUDIT outputs the following to the lst: * 1. side-by-side comparison of all audit data set attributes * 2. a comparison of the CONTENTS variables output object from * the source and target libraries. * 3. a comparision of the CONTENTS engine host output object * from the source and target libraries. * 4. results of a comparison of the source library audit file * with the pre-MIGRATE audit file records in the target library * 5. information about the post-MIGRATE library audit file records * in the target library * * The default behavior of CHECKAUDIT is to output only those * data set attributes and variable information which differs * between the source and target libraries. To output all data, * including data that is the same in both libraries, submit * the following: * %checkaudit(showall=yes); *----------------------------------------------------------------*; %macro checkaudit(showall); %do i=1 %to &lib1taudit; %let ishere=%sysfunc(exist(lib2.&&lib1audit&i)); %if &ishere=1 %then %do; * 1. "smart compare" of data set attributes; ods output attributes=ods.atr1(keep=label1 cvalue1 where=(label1 not in (" ", "Data Set Name", "Created", "Last Modified"))) attributes=ods.atr2(keep=label2 cvalue2 where=(label2 ne " ")) EngineHost=ods.lib1_audit_eng&i(keep=label1 cvalue1 where=(label1 not in ("File Name"))); ods listing close; %if %sysfunc(index(&&lib1audit&i, #)) gt 0 %then %do; proc contents data=lib1.%str("&&lib1audit&i")n(type=audit);run; %end; %else %do; proc contents data=lib1.&&lib1audit&i(type=audit);run; %end; ods listing; data ods.atr1(rename=(label1=attribute cvalue1=source)); set ods.atr1; run; data ods.atr2(rename=(label2=attribute cvalue2=source)); set ods.atr2; run; data ods.lib1_audit_atr&i; set ods.atr1 ods.atr2; run; proc sort data=ods.lib1_audit_atr&i;by attribute;run; data ods.lib1_audit_eng&i(rename=(label1=attribute cvalue1=source)); set ods.lib1_audit_eng&i; run; proc sort data=ods.lib1_audit_eng&i;by attribute;run; ods output attributes=ods.atr1(keep=label1 cvalue1 where=(label1 not in (" ", "Data Set Name", "Created", "Last Modified"))) attributes=ods.atr2(keep=label2 cvalue2 where=(label2 ne " ")) EngineHost=ods.lib2_audit_eng&i(keep=label1 cvalue1 where=(label1 not in ("File Name"))); ods listing close; %if %sysfunc(index(&&lib1audit&i, #)) gt 0 %then %do; proc contents data=lib2.%str("&&lib1audit&i")n(type=audit);run; %end; %else %do; proc contents data=lib2.&&lib1audit&i(type=audit);run; %end; ods listing; data ods.atr1(rename=(label1=attribute cvalue1=target)); set ods.atr1; run; data ods.atr2(rename=(label2=attribute cvalue2=target)); set ods.atr2; run; data ods.lib2_audit_atr&i; set ods.atr1 ods.atr2; run; proc sort data=ods.lib2_audit_atr&i;by attribute;run; data ods.lib2_audit_eng&i(rename=(label1=attribute cvalue1=target)); set ods.lib2_audit_eng&i; run; proc sort data=ods.lib2_audit_eng&i;by attribute;run; data ods.comp_audit_atr&i; merge ods.lib1_audit_atr&i(in=in1) ods.lib2_audit_atr&i(in=in2); by attribute; if in1 or in2; run; data ods.comp_audit_eng&i; merge ods.lib1_audit_eng&i(in=in1) ods.lib2_audit_eng&i(in=in2); by attribute; if in1 or in2; run; title2 "%sysfunc(left(%sysfunc(trim(&&lib1audit&i))))"; title3 "Number &i of %sysfunc(left(%sysfunc(trim(&&lib1taudit)))) audit files in source library"; %if &showall=yes %then %do; proc print data=ods.comp_audit_atr&i; title4 "Comparison of PROC CONTENTS header information"; title5 "Number 1 of 5 reports for this file (from checkaudit macro)"; var attribute source target; run; proc print data=ods.comp_audit_eng&i; title4 "Comparison of PROC CONTENTS engine/host information"; title5 "Number 2 of 5 reports for this file (from checkaudit macro)"; var attribute source target; run; %end; %else %if &showall ne yes %then %do; data ods.comp_audit_atr&i; set ods.comp_audit_atr&i; if source ne target; run; proc print data=ods.comp_audit_atr&i; title4 "Comparison of PROC CONTENTS header information"; title5 "Note: all other header information was the same"; title6 "Number 1 of 5 reports for this file (from checkaudit macro)"; var attribute source target; run; data ods.comp_audit_eng&i; set ods.comp_audit_eng&i; if source ne target; run; proc print data=ods.comp_audit_eng&i; title4 "Differences in PROC CONTENTS engine/host information"; title5 "Note: all other engine/host information was the same"; title6 "Number 2 of 5 reports for this file (from checkaudit macro)"; var attribute source target; run; %end; ***** 2. output variables object ; ods output variables=ods.audit1var&i(drop=member); ods listing close; %if %sysfunc(index(&&lib1audit&i, #)) gt 0 %then %do; proc contents data=lib1.%str("&&lib1audit&i")n(type=audit);run; %end; %else %do; proc contents data=lib1.&&lib1audit&i(type=audit);run; %end; ods listing; proc sort data=ods.audit1var&i;by num variable;run; ods output variables=ods.audit2var&i(drop=member); ods listing close; %if %sysfunc(index(&&lib1audit&i, #)) gt 0 %then %do; proc contents data=lib2.%str("&&lib1audit&i")n(type=audit);run; %end; %else %do; proc contents data=lib2.&&lib1audit&i(type=audit);run; %end; ods listing; proc sort data=ods.audit2var&i;by num variable;run; data ods.audit1var&i(rename=(type=s_type len=s_len pos=s_pos format=s_format)); set ods.audit1var&i; run; data ods.audit2var&i(rename=(type=t_type len=t_len pos=t_pos format=t_format)); set ods.audit2var&i; run; data ods.audit3var&i; merge ods.audit1var&i(in=in1) ods.audit2var&i(in=in2); by num variable; if in1 or in2; run; %if &showall=yes %then %do; title4 "Comparison of PROC CONTENTS variable information"; title5 "s=source library, t=target library"; title6 "Number 3 of 5 reports for this file (from checkaudit macro)"; proc print data=ods.audit3var&i noobs; var num variable s_type t_type s_len t_len s_pos t_pos s_format t_format; run; %end; %else %if &showall ne yes %then %do; data ods.audit3var&i; length result $50.; retain count 0; set ods.audit3var&i end=eof; if s_type=t_type and s_len=t_len and s_pos=t_pos and s_format=t_format then do; result="OK"; end; else do; result="PROBLEM"; count+1; end; if eof then do; if count=0 then do; result="type, len, pos and format agreed for all variables"; keep result; output; end; end; run; title4 "Comparison of PROC CONTENTS variable information"; title5 "Number 3 of 5 reports for this file (from checkaudit macro)"; proc print data=ods.audit3var&i noobs; run; %end; title6; %if &showall=yes %then %do; title4 "Contents of audit file from source library"; title5 "Number 5 of 5 reports for this file (from checkaudit macro)"; proc print data=lib1.%str("&&lib1audit&i")n(type=audit);run; title4 "Contents of audit file from target library"; title5 "Number 5 of 5 reports for this file (from checkaudit macro)"; proc print data=lib2.%str("&&lib1audit&i")n(type=audit);run; %end; %else %if &showall= %then %do; *-------------------------------------------------------------------------------* * separate the new audit records created by MIGRATE from the migrated audit file *-------------------------------------------------------------------------------*; data ods.testaud&i; rid=_n_; set lib2.%str("&&lib1audit&i")n(type=audit); run; proc sort data=ods.testaud&i;by rid _atmessage_;run; *--------------------------------------------------------------------------------* * MIGRATE always adds at least one record to the end of an audit file where * _atmessage_= "MIGRATE". If an audit trail was suspended prior to migration, * MIGRATE adds one more record, where _atmessage_="SUSPEND". Use this information * to identify the cutoff point between "old" and "new" audit file records. *--------------------------------------------------------------------------------*; data _null_; set ods.testaud&i end=eof; by rid _atmessage_; lag_at=lag(_atmessage_); if eof then do; if lag_at= "MIGRATE" then call symput("cutoff", rid-2);*the current record must be "suspend", so 2 records were added; else if lag_at ne "MIGRATE" then call symput("cutoff", rid-1);*the current record must be "migrate", so 1 record was added; end; run; data ods.audit_short&i ods.audit_new&i; set lib2.%str("&&lib1audit&i")n(type=audit); if _n_ le &cutoff then output ods.audit_short&i; if _n_ gt &cutoff then output ods.audit_new&i; run; *-------------------------------------------------------------------------------* * create a "copy" of the original audit file to avoid a "type" difference * when comparing its data to the "audit_short" data set created above. *-------------------------------------------------------------------------------*; data ods.audit_source&i; set lib1.%str("&&lib1audit&i")n(type=audit); run; *-------------------------------------------------------------------------------* * compare the data in audit file in the source library to the data in the * "shortened" audit file in the target library *-------------------------------------------------------------------------------*; proc compare base=ods.audit_source&i comp=ods.audit_short&i noprint; run; %if &sysinfo=0 %then %do; data ods.audcompo&i; length result $100.; result="OK: pre-MIGRATE records in migrated audit file match original"; run; %end; %else %if &sysinfo ne 0 %then %do; data ods.audcompo&i; length result $100.; result="PROBLEM: pre-MIGRATE records in migrated audit file do NOT match original"; run; %end; title4 "Results of comparision of pre-MIGRATE records in audit file in source and target libraries"; title5 "Number 4 of 5 reports for this file (from checkaudit macro)"; proc print data=ods.audcompo&i noobs;run; *-------------------------------------------------------------------------------* * Create a macro variable which contains the last "date modified" record * from last observation in source library audit file. *-------------------------------------------------------------------------------*; data _null_; %global last_date; set lib1.%str("&&lib1audit&i")n(type=audit) end=eof; if eof then do; call symput("last_date", put(_atdatetime_, datetime20.)); end; run; *-------------------------------------------------------------------------------* * Check the records added to the migrated audit file. *-------------------------------------------------------------------------------*; data ods.audcompn&i(keep=result); length result $100.; set ods.audit_new&i end=eof; retain count 0; if _n_=1 then do; if _atopcode_ ne "AM" then count+1; if _atmessage_ ne "MIGRATE" then count+1; if x ne . then count+1; if _atobsno_ ne . then count+1; if _atreturncode_ ne . then count+1; if _atdatetime_ lt input("&last_date", datetime20.) then count+1; if _atuserid_ =" " then count+1; end; else if _n_=2 then do; if _atopcode_ ne "AS" then count+1; if _atmessage_ ne "SUSPEND" then count+1; if x ne . then count+1; if _atobsno_ ne . then count+1; if _atreturncode_ ne . then count+1; if _atdatetime_ lt input("&last_date", datetime20.) then count+1; if _atuserid_ =" " then count+1; end; if eof then do; if count=0 then result="OK: post-MIGRATE records in migrated audit file contain expected values"; else if count ne 0 then result="PROBLEM: post-MIGRATE records in migrated audit file contain unexpected values"; output; end; run; title4 "Status of post-MIGRATE records in target library audit file"; title5 "Number 5 of 5 reports for this file (from checkaudit macro)"; proc print data=ods.audcompn&i noobs;run; %end; *clean up data sets created in the ODS library by this macro; proc datasets lib=ods nolist; delete atr1 atr2 lib1_audit_eng&i lib1_audit_atr&i lib2_audit_eng&i lib2_audit_atr&i comp_audit_atr&i comp_audit_eng&i audcompn&i audcompo&i audit1var&i audit2var&i audit3var&i audit_new&i audit_short&i audit_source&i comp_audit_atr&i comp_audit_eng&i testaud&i ; quit; %end; %else %do; data ods.nothere; note="No validation will be performed"; run; title2 "&&lib1audit&i"; title3 "Number &i of %sysfunc(compress(&&lib1taudit)) audit files in source library"; title4 "Member is present in LIB1 but was not MIGRATED to LIB2"; proc print data=ods.nothere noobs;run; %end; %end; title3; title4; title5; title6; %mend checkaudit; *----------------------------------------------------------------* * CHECKCATALOG outputs the following to the lst: * 1. COMPARE of catalog metadata in source library against * catalog metadata in target library. *----------------------------------------------------------------*; %macro checkcatalog; %do i=1 %to &lib1tcatalog; %let ishere=%sysfunc(exist(lib2.&&lib1catalog&i, CATALOG)); %if &ishere=1 %then %do; ods output catalog_random=ods.lib1_catalog&i(drop=crdate moddate); ods listing close; proc catalog catalog=lib1.&&lib1catalog&i; contents; run; quit; ods listing; ods output catalog_random=ods.lib2_catalog&i(drop=crdate moddate); ods listing close; proc catalog catalog=lib2.&&lib1catalog&i; contents; run; quit; ods listing; title2 "%sysfunc(left(%sysfunc(trim(&&lib1catalog&i))))"; title3 "Number &i of %sysfunc(compress(&&lib1tcatalog)) catalogs in source library"; title4 "PROC COMPARE of metadata of catalog in source and target libraries (from checkcatalog macro)"; proc compare base=ods.lib1_catalog&i comp=ods.lib2_catalog&i briefsummary listall; run; *clean up data sets created in the ODS library by this macro; proc datasets lib=ods nolist; delete lib1_catalog&i lib2_catalog&i ; quit; %end; %else %do; data ods.nothere; note="No validation will be performed"; run; title2 "&&lib1catalog&i"; title3 "Number &i of %sysfunc(compress(&&lib1tcatalog)) catalogs in source library"; title4 "Member is present in LIB1 but was not MIGRATED to LIB2"; proc print data=ods.nothere noobs;run; %end; %end; title2; title3; title4; %mend checkcatalog; *----------------------------------------------------------------* * At present, CHECKVIEW is intended to be run only on libraries * which contain data step views and SQL views. Use on libraries * which contain SAS/ACCESS views at your own risk. * * CHECKVIEW can produce validation output for only SQL views. * * CHECKVIEW compares a data set created from a view in the source * library to a data set created from the same view that's been * migrated to the target library. Please note these data sets * are in the ODS library, and are created using the ODS library's * engine. * * CHECKVIEW can also print a flexible number of observations * from each of the data sets. * To print the first 10 observations, submit the following: * * %checkview(printview=yes) * * You can also specify the number of observations by use of the * "obs" argument: * * %checkview(printview=yes, obs=50) * %checkview(printview=yes, obs=2) *----------------------------------------------------------------*; %macro checkview(printview, obs); %global view_type; %do i=1 %to &lib1tview; %let ishere=%sysfunc(exist(lib2.&&lib1view&i, view)); %if &ishere=1 %then %do; *----------------------------------------------------------------* * Determine whether or not the view is a Data Step view. If * so, do not validate the view. *----------------------------------------------------------------*; ods output attributes=ods.lib1_v_atr&i(keep=label1 cvalue1 where=(label1 in ('Engine'))); ods listing close; proc contents data=lib1.&&lib1view&i;run; ods listing; data _null_; set ods.lib1_v_atr&i; call symput("view_type", cvalue1); run; %if &view_type=SASDSV %then %do; data ods.lib1_v_atr&i(rename=(Label1=attribute cvalue1=value)); set ods.lib1_v_atr&i; run; title2 &&lib1view&i; title3 "NOTE: This member is a data step view"; title4 "Validation cannot be performed on data step views"; title5 "output below is from CONTENTS Engine/Host Data"; proc print data=ods.lib1_v_atr&i noobs;run; title3; title4; title5; %end; %else %if &view_type ne SASDSV %then %do; data ods.source_&&lib1view&i; set lib1.&&lib1view&i; run; data ods.target_&&lib1view&i; set lib2.&&lib1view&i; run; title2 "&&lib1view&i"; title3 "comparison of data sets created from source and target library versions of view"; proc compare base=ods.source_&&lib1view&i comp=ods.target_&&lib1view&i briefsummary listall; run; %if &printview=yes %then %do; %if &obs= %then %let obs=10; proc print data=ods.source_&&lib1view&i(obs=&obs); title3 "first &obs observations from data set created from source library version of %sysfunc(left(%sysfunc(trim(&&lib1view&i))))"; run; proc print data=ods.target_&&lib1view&i(obs=&obs); title3 "first &obs observations from data set created from target library version of %sysfunc(left(%sysfunc(trim(&&lib1view&i))))"; run; %end; %end; *clean up datasets created in ODS library by this macro; proc datasets lib=ods nolist; delete lib1_v_atr1 lib1_v_atr2 source_&&lib1view&i target_&&lib1view&i ; run; quit; %end; %else %do; data ods.nothere; note="No validation will be performed"; run; title2 "&&lib1view&i"; title3 "Number &i of %sysfunc(compress(&&lib1tview)) views in source library"; title4 "Member is present in LIB1 but was not MIGRATED to LIB2"; proc print data=ods.nothere noobs;run; %end; %end; title2; title3; title4; title5; %mend checkview; *----------------------------------------------------------------* * macro %checkindex produces validation output in the SAS * output window describing Indexes and/or Integrity Constraints * in the source and target libraries. * * Please note that %mig_indexes and %mig_indexes(lib=LIB2) must * both be run prior to running %checkindex. * * The default behavior of %checkindex is to produce COMPARE * output in the SAS output window. To output the Index and/or * Integrity Constraint information instead, submit: * * %checkindex(showall=yes); * *----------------------------------------------------------------*; %macro checkindex(showall); %if &index_here=Y %then %do; %if &showall ne yes %then %do; title2 "comparison of indexes in source and target libraries"; proc compare base=ods.lib1_idx comp=ods.lib2_idx listall briefsummary; run; %if &ics_here=Y %then %do; title2 "comparison of Integrity Constraints in source and target libraries"; proc compare base=ods.lib1_ics comp=ods.lib2_ics listall briefsummary; run; %end; %end; %else %if &showall eq yes %then %do; title2 "Indexes in source library before MIGRATE"; proc print data=ods.lib1_idx;run; title2 "Indexes in target library after MIGRATE"; proc print data=ods.lib2_idx;run; %if &ics_here=Y %then %do; title2 "Integrity Constraints in source library before MIGRATE"; proc print data=ods.lib1_ics;run; title2 "Integrity Constraints in target library after MIGRATE"; proc print data=ods.lib2_ics;run; %end; %end; %end; %mend checkindex; *----------------------------------------------------------------* * CHECKEM uses the memtype flags created in MIG_SOURCE to * run the "QC check" macros for any memtypes that were in the * source library prior to the MIGRATE. * The default behavior of CHECKEM is to produce "slim" output * (only those file attributes that are different in the source * and target libraries): * * %checkem; * * To output all file attributes, submit the following: * * %checkem(showall=yes); *----------------------------------------------------------------*; %macro checkem(showall); %if &showall= %then %do; %if &data_here=Y %then %do;%checkdata;%end; %if &view_here=Y %then %do;%checkview;%end; %if &audit_here=Y %then %do;%checkaudit;%end; %if &index_here=Y %then %do;%checkindex;%end; %end; %else %if &showall ne %then %do; %if &data_here=Y %then %do;%checkdata(showall=yes);%end; %if &view_here=Y %then %do;%checkview(printview=yes);%end; %if &audit_here=Y %then %do;%checkaudit(showall=yes);%end; %if &index_here=Y %then %do;%checkindex(showall=yes);%end; %end; %if &catalog_here=Y %then %do;%checkcatalog;%end; %mend checkem; /*-------------------------------------------------------------- * * SAS TEST LIBRARY TRAILER * * SYSTEMS: 9.1 or later * PRODUCT: MIGRATE * * CREATED: 25 November 2002. * UPDATE: 25 February 2003 dawieh revised %checkem macro * 20 March 2003 dawieh revised %checkview macro * 21 March 2003 dawieh revised %mig_in_lib to use * CONTENTS instead of DATASETS to * output library members (to allow * this tool to work on SEQ source * libraries) * 25 March 2003 dawieh revised logic for %ics_here * and removed title5 from %checkcatalog * 22 April 2003 dawieh revised logic for %checkindex * 24 April 2003 dawieh initialized memtype counter * variables to zero to avoid WARNINGs * when certain memtypes do not exist in * source libraries. * 29 April 2003 dawieh added memtype counter variables * to %global statement. * 2 May 2003 dawieh revised logic for memtype * counter macros. * 17 June 2003 dawieh revised logic for memtype flag * variables *--------------------------------------------------------------*/