OPTIONS LINESIZE=140 PAGESIZE=100 NOCENTER NODATE NONUMBER fmtsearch=(new.w2form); **********************************************************************************************; * WATCH II Study PROGRAM ; * PROGRAM NAME LOCATION DATE PROGRAMMER ; Title1 "Source:w2py04p25.SAS WATCH II 01/29/2004 PY & ES" ; * Description: : * (1) Create a format file from library.formats, new.w2form : * (2) Get a data set. ; * (3) Merge the data set and the format file using proc SQL ; * (4) Create a template html file in Dreamweaver, modify and copy its source code over, ; * and make the souce code into stream. If there are errors for some of symbols (s) ; * such as double quotes " and percent sign %, then embrace it with the sinle quotes,; * then double quotes like " 's' ". Repeat the process as long as there are no ; * symbols causing errors in the stream. ; * (5) Generage html file. : **********************************************************************************************; LIBNAME new 'J:\Projects\watchII\data\new'; LIBNAME tmp 'J:\Projects\watchII\temp'; *** path for the html output inside macro; ODS LISTING; ** writting ouput to the SAS output window**; ODS HTML CLOSE; *** get format file from format catalog; proc format library=new.w2form cntlout=fmt; run; %MACRO CODEBOOK(fmtin=, din=, htmlout=); *** get format file; data fmtfile; set &fmtin; rename label=labelf; title2 'Format file'; run; *** get data set; proc contents data=&din out=contfile2 (KEEP=name label format); title2 'Contents of data set tmp2'; run; *** rename variable and add id; data contfile; set contfile2; rename format=FMTNAME; ID=_N_; run; PROC PRINT DATA=contfile; TITLE2 "List of contfile"; RUN; PROC PRINT DATA=fmtfile; TITLE2 "Fmtfile"; RUN; ***************************************************************** *** join 2 tables by joining two tables by cartesian, one to many; *****************************************************************; proc sql; create table matched as select * from contfile as l, fmtfile as r where l.fmtname=r.fmtname; run; quit; proc print data=matched; title2 'data set called matched'; run; *************************************************** *** merger two tables to get where unmatch records; **************************************************; proc sort data=contfile; by fmtname; proc sort data=fmtfile; by fmtname; run; data unmatch; merge contfile (in=basei) fmtfile (in=fin); by fmtname; if basei and not fin; run; proc print data=unmatch; title2 'data set called unmatched'; run; ***************************** *** combine match and unmatch; *****************************; data c (keep=name id label labelf); set matched unmatch; proc print; run; proc print; title2 'Combined data set'; run; proc sort data=c; by name; run; ************************************************ *** remove double name and only keep first name ************************************************; data C1; set C; by name; *** remove duplicate names in variable and label; if first.name = 0 then do; name =' '; label=' '; end; run; proc sort data=c1; by id; run; proc print data=c1; title2 'final data set to create html file'; run; *** specify path for the output; FILENAME test1 "J:\Projects\watchII\temp\&htmlout"; DATA _NULL_; SET c1 END=lastrec; BY id; FILE test1; *file print; if _N_ = 1 then put ""/ ""/ "
"/ "| Variable "/ " | "/
" Description "/ " | "/
"
| " name " "/ " | "/
" " label " | "/ "
| " name " "/ " | "/
" "label" | "/ "||
| " "&" "nbsp; | "/ ""/
"
| "/
"