*
; /* Well, nobody offered exactly what I wanted several weeks or months ago when I asked for help getting SAS to produce HTML code, so I did it myself and here it is. Rather than being output from TABULATE or processing TABULATE output, I decided that it would be more useful if it just created an HTML (Version 2 or 3?) table from a given SAS dataset. The current version of Netscape handles the output of this macro quite nicely. Please use it, break it (if possible), criticize it, and let me know how you like it (whether you do or not). The %var macro which is called by %SAS2HTML is appended... John -- ** http://delphi.colorado.edu/~irm/pers/jdshome.html ** -- John D. Smith, IRM, CB 50, UofColo, Boulder, CO 80309 - (303) 492-9473 light modified by Arnold Schick ---------------------------------------------------------*/ %macro SAS2html (sdsetnam, outfname, title=, keep=, where=); * writes all vars & observations from a SAS dataset to an HTML table ; * Sample call: *sas2html(sasuser.fitness,temp.htm, where=); * Parameters: sdsetnam = Name of SAS dataset to be converted to a table. outfname = data set name for the output file. keep = optional keep statement controls the variables that will be printed. where = optional where statement to subset the observations to be printed. ; * requires the *VAR macro; ; * cut the operating system loose; options noxwait noxsync; %let sdsetnam = %upcase(&sdsetnam); %let keep = %upcase(&keep); %if &sdsetnam eq %str() %then %do; %put NOTE: The DATASET was not specified, using the _last_ dataset; %let ddname = %scan(&sysdsn,1); %let dsetnam= %scan(&sysdsn,2); %end; %else %do; %let ddname = %scan(&sdsetnam,1); %let dsetnam= %scan(&sdsetnam,2); %end; %if &outfname eq %str() %then %do; %let outfname = tablfile.htm; %put NOTE: The Output File Name was not specified, so writing to &outfname.; %end; %global nobs nvar; filename htmlout "&outfname"; * get information from the dictionary about the dataset to be copied by calling the *var macro. ; %var(&ddname, &dsetnam, prntvars=N); * proc sql is still running. ; select nobs into: nobs from dictionary.tables where libname eq "&DDNAME" and memname eq "&DSETNAM"; select nobs into: nVAR from dictionary.tables where libname eq "WORK" and memname eq "VAR"; quit; %if %eval(&nobs gt 0) %then %do; * write a put statement in a temporary file based on the information in the work.var dataset. cumulate information about the total width of the data. ; data _null_; set var %if &keep ne %str() %then (where=(indexw("&keep",name))); end=eof; * put the dataset labels as the column headers; file htmlout; if _n_ eq 1 then do; %if &title ne %str() %then put '' / "&title" / '
' %str(;); %else put '' / "SAS dataset &sdsetnam" / '
'%str(;); put '
' name $ ' | '; else put '' label $ ' | '; if eof then put '" ' name $8. +3 format $ ' " | " ' /; end; else do; if format eq ' ' then format = '10.2'; put ' "" ' name $8. +3 format $ ' " | " ' /; end; if eof then put ';'; run; * write the actual data. ; data _null_; set &ddname..&dsetnam %if &where ne %str() %then (where=(&where)); end=eof; file htmlout mod; put '