/* IMPORTANT Notes (4/2015): 1. Setup in /pub/data/system/Tools/revise_datasets_data_sets.sas can be used to revise the Datasets.html set for a filetype. It changes the length of some variables, creates some new ones and drops some old. It parses the years parm to create the latest_years parm. 2. After revising (per item 1) you will probably want to specify sortby=descending LatestYear setgroup memname and groupby=LatestYear. This macro will generate a report (html page) summarizing the datasets within a data library. It will use data contained in the datasets dataset of the specified data lib along with data obtained from running proc contents on the library. The generated page contains, among other things, hyperlinks to our metadata (display datasets dataset) application. Output is written to the file Datasets.html in the directory (folder) corresponding to libname (derived from libpath). Note: originally named gendsrpt, changed to current name 2-6-03. Code by John Blodgett, OSEDA, under contract with the Missouri Census Data Center, 2/03. Update History: 8/12/2003 8:00AM: Modifying name column to link to dexter instead of callapp (old xtract). 6/30/2004 10:47AM: Adding memindex option to create the memname index. 12/27/2004 11:37AM: Checking for existing of a file signaling data have been converted for v9 and generating appropriate value for _service parm when invoking uex2dex. 2/4/2008 1:49:16 PM: Adding mcdc title and link to home page. 7/1/2009: Adding code to check for duplicate libname, memname obs and keep only the one with the latest value of modified. 10/22/09: Fixed 2 typos in code added 7/1 . 1/14/2010: Fix bug that was causing all templates to be marked with sortprio='X' (!!) 11/2/2010: Adding sortby and groupby parms to make sorting the datasets.html page more flexible. 02/12/2013: Display date and time last updated. 03/07/2015: Replace Eng w Years in display. */ %macro gendshtm( revdate=2/12/2013 1:36:09 PM, libname=, /* Library to generate the report for. A libname stmt must be used in the invoking program to define this libref, normally with read/write access. */ filetype=, /* Libref used to find the datasets dataset. I.e. it is in &filetype..datasets. If not specified assigned value of libname. */ runprocc=0, /* Specify runprocc=1 to indicate you want/need to run the proc contents step. If runprocc=0 and the .datasets_contents dataset does not exist then the program will generate it anyway, as if runprocc=1 had been specified. */ sortby=sortprio setgroup descending years memname, groupby=years, /* Allow flexibility in sorting and displaying the datasets.html page. groupby is the name of a variable within the sortby list. */ memindex=1, /* Specify memindex=0 to skip creating the memname index on the datasets dataset. */ debug=0 ); %if &debug %then %put **** gendshtm, rev. &revdate, begin execution ****; %if &filetype=%str() %then %let filetype=&libname; %local service; %let service=MCDC; proc sort data=&filetype..datasets out=tempsort nodupkeys; by libname memname; run; data _null_; if 0 then set tempsort nobs=_nobsnodups; if 0 then set &filetype..datasets nobs=_nobswithdups; if _nobsnodups=_nobswithdups then flag="y"; else flag="n"; call symput('flag',flag); stop; run; %if &flag=n %then %do; proc sort data=&filetype..datasets out=tempsort ; by libname memname modified; run; data &filetype..datasets; set tempsort; by libname memname; if last.memname; *-- Keep the one with the latest modified value. ; run; proc datasets library=&filetype nolist; modify datasets; index delete memname dataset; *-- In case it already exists ; index create memname ; index create dataset=(libname memname)/unique; quit; %let memindex=0; %end; %if &memindex %then %do; proc datasets library=&filetype nolist; modify datasets; index delete memname dataset; *--in case it already exists--; index create memname ; index create dataset=(libname memname)/unique; quit; %end; %if &runprocc=1 or (%sysfunc(exist(&libname..datasets_contents))=0) %then %do; %let runprocc=1; *-- Generate a Datasets.html file in the current directory based on dataset info from the datasets dataset and proc contents. ; proc contents data=&libname.._all_ noprint out=datasets_contents(keep=memname memtype memlabel nobs crdate engine varnum where=(varnum=1 and lowcase(memname) ne 'datasets_contents') rename=(crdate=created)); run; data &libname..datasets_contents; length libname $8; retain libname "&libname"; set datasets_contents; memname=lowcase(memname); if memlabel="'" then memlabel=" "; drop varnum; format created datetime7.; run; proc sort data=&libname..datasets_contents; by memname; run; %end; %if %sysfunc(exist(&filetype..datasets))=0 %then %do; %put; %put; %put ******ERROR: No datasets dataset found in specified library &filetype ******; %put &filetype..datasets; %goto endmac; %end; data &filetype..datasets ; *-- We update the datasets dataset per contents data. ; update &filetype..datasets (in=indatasets) &libname..datasets_contents(rename=(memlabel=memlabelC) in=incontents); by memname; if memlabel=' ' then memlabel=memlabelC; drop memlabelC; if not indatasets then sortprio="9"; if not incontents and &runprocc and memtype in ('DATA','VIEW') then sortprio='X'; *-- Marked for delete ; if setgroup= ' ' then setgroup=geouniv; run; proc datasets library=&filetype nolist; *-- We just updated the dataset so we have to replace indices. ; modify datasets; index delete dataset memname; index create dataset=(libname memname) / unique; index create memname; quit; data allsets; *-- Reversing the order of the datasets in this update step. We want data coming from the _contents set to replace corr variables in the datasets dataset. ; update &filetype..datasets (where=(SortPrio ne "X" and not( memname=:'_template') and libname="&libname" ) in=indatasets) &libname..datasets_contents(rename=(memlabel=memlabelC)); by memname; if memlabel=' ' then memlabel=memlabelC; drop memlabelC; if not indatasets then sortprio="9"; format created datetime7.; if indatasets then call symput('libpath',trim(libpath)); if setgroup= ' ' then setgroup=geouniv; run; proc sort data=allsets; *by SortPrio SetGroup Geouniv SubType descending years Memname; by &sortby; run; %if &sysscp=WIN %then %let slash=%str(\); %else %let slash=%str(/); proc format; *-- The $tb format will cause a character to be put in the cell so it will not be empty when value is blank. ; *-- We leave all those blanks ON PURPOSE to make the format length sufficiently long. ; value $tb ' '=' ' other=[$char200.]; run; data _null_; set allsets end=last; * by SortPrio SetGroup; by &sortby; %let libpath= %sysfunc(pathname(&libname)); file "&libpath&slash.Datasets.html" lrecl=500; if _n_=1 then do; put ''; put "

Summary of Data Tables in &libpath

"; put '

With Links to Detailed Metadata

'; put "
Last Updated on &sysdate at &systime
"; put ''; end; _n+1; if mod(_n,14)=1 or (first.&groupby and _n gt 12) then do; *-- Repeat the headers every 14 observations or when a new group starts but no more than every 12. ; _n=1; put ''; put ''; end; length _url $255; retain filetype "&filetype"; _url='/cgi-bin/broker?_PROGRAM=utils.metadata.sas&libname='||trim(libname)|| '&memname='||trim(memname); *-- Platform dependent; if scan(libpath,-1) ne filetype then _url=trim(_url)||'&libpath='||urlencode(trim(libpath)); _url=quote(trim(_url)); length _xref $200; length _view $1; if memtype='VIEW' then _view='1'; else _view='0'; *-- Flag for uex2dex pgm ; *-- No longer accessing URLxtract variable -- we always generate _xref pointing to Dexter. ; _xref='"'||'/cgi-bin/broker?_PROGRAM=utils.uex2dex.sas&path='||"&libpath"||'&dset='||trim(memname)||'&view='||_view||'"'; *else _xref="/cgi-bin/callapp.pl?dir=&libpath"||'&dset='||trim(memname)||'&form=xtract.html'; put ''; else put '—'; put ''; if last then do; put '
#Name & data linkLabelRowsColsGeographic universeUnitsYear(s)MetadataSize (KB)Created
' _n_ '' memname '' memlabel $tb. '' nobs comma7. '' nvars comma7. '' GeoUniv $tb. '' Units $tb. '' years ''; if GeoUniv ne " " or Description ne " " then put 'details' kbytes comma9. '' created datetime7. '
'; end; run; %endmac: %mend gendshtm;