/*------------------------------------------------------------------------ © Copyright 2011-2013 University of Manitoba This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . -------------------------------------------------------------------------------- Programmer: Say Hong Based on the previous work by Mahmoud Azimaee Please direct questions and comments to info@cpe.umanitoba.ca Feb. 26, 2013 This macro generate an overview table that contains dataset name, dataset label, number of records and number of fields Macro Parameters: Domain = Libname of the dataset Db = Dataset prefix or Space separated list of dataset name or cluster dataset name memnum = Space separated list of cluster members ------------------------------------------------------------------------------------*/ %macro dq_contents(domain=, db=, memnum=); %if %sysfunc(countw(&db)) = 1 %then %do; proc sql noprint; select memname into :dsn separated by ' ' from dictionary.members where libname = %upcase("&domain") and substr(memname, 1, %length(&db)) = %upcase("&db"); quit; %end; %else %let dsn = &db; %let n_dsn = %sysfunc(countw(&dsn)); %do i = 1 %to &n_dsn; %if &memnum ^= and %upcase(&memnum) ^= ALL %then %do; ods output enginehost=clsmem; proc contents data=&domain..%scan(&dsn, &i) out=contents; run; ods output close; proc sql noprint; select distinct memlabel into :memlabel from contents; quit; data _null_; set clsmem; if label1 = 'Cluster Members are' then call symputx('clsmem', cvalue1); run; proc datasets nolist memtype=data lib=work; delete clsmem; quit; /* obtain the cluster members */ %let nmem = %sysfunc(countw(&memnum)); %let members=; %do j = 1 %to &nmem; %let mem = %scan(&memnum, &j); %let temp=%scan(%scan(%bquote(&clsmem), &mem, %str(,)), 1, '('); %let members = &members &temp; %end; %let members = %sysfunc(tranwrd(&members, %str( ), %str(, ))); /* */ %if %sysfunc(countw(&memnum)) = 1 %then %do; proc contents data=&domain..%scan(&dsn, &i)(memnum=&memnum) out=contents&i noprint; run; data contents&i; length clustername clustermembers $100; retain clustername "%scan(%upcase(&dsn), &i)" clustermembers "&members"; set contents&i; run; %end; %else %if %sysfunc(countw(&memnum)) > 1 %then %do; %do j = 1 %to &nmem; %let mem = %scan(&memnum, &j); data data&j; set &domain..%scan(&dsn, &i)(memnum=&mem); run; %end; data %scan(&dsn, &i); set data1-data%sysfunc(countw(&memnum)); run; proc contents data=%scan(&dsn, &i) out=contents&i noprint; run; proc datasets nolist memtype=data lib=work; delete data1-data&nmem %scan(&dsn, &i); quit; data contents&i; length clustermembers $500; set contents&i; libname = %upcase("&domain"); clustername = "%scan(&dsn, &i)"; clustermembers = "&members"; memlabel = "&memlabel"; run; %end; %end; %else %do; proc contents data=&domain..%scan(&dsn, &i) out=contents&i noprint; run; %end; %end; data contents; set contents1-contents&n_dsn; run; proc sort data=contents; by memname; run; data overview; retain libname _all_; set contents; by memname; if first.memname then nvar=0; nvar+1; if last.memname; %if &memnum= or %upcase(&memnum)=ALL %then %do; keep libname memname memlabel nobs nvar; label nvar = 'Number of Fields' nobs = 'Number of Records' libname = 'Domain' memname = 'SPDS Table' memlabel = 'Dataset Label'; %end; %else %do; keep libname clustername clustermembers memlabel nobs nvar; label nvar = 'Number of Fields' nobs = 'Number of Records' libname = 'Domain' clustername = 'SPDS Cluster Name' clustermembers = 'Cluster Members' memlabel = 'Dataset Label'; %end; run; %if %substr(&dq_dir, %length(&dq_dir), 1) = \ %then %let dq_dir = %substr(&dq_dir, 1, %length(&dq_dir) - 1); proc export data=overview outfile="&dq_dir\&dq_name..xls" dbms=excelcs label replace; sheet = 'overview'; run; proc print data=overview; run; proc datasets nolist memtype=data lib=work; delete contents1-contents&n_dsn contents overview; quit; %mend dq_contents;