/* *<=====e-mail header converted to a comment to document orginal source Date: Wed, 1 Nov 1995 10:12:33 -0700 From: "John D. Smith" Subject: SAS to HTML table macro enclosed FYI 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 -------------------------------------------- ====================================================== */ %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; ***<===did not work under AIX: 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 ''; end; if label eq ' ' then put ''; else put ''; if eof then put ''; file 'temp00.sas'; if _n_ eq 1 then put 'put'; if type eq: 'c' then do; if format eq ' ' then format = '$'; *<==============fix spelling in following line-jgb================; **put ' "" ' /; put ' "" ' /; end; else do; if format eq ' ' then format = '10.2'; put ' "" ' /; 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 ''; %include 'temp00.sas'; ; put ''; if eof then put '
' name $ '' label $ '
" ' name $8. +3 format $ ' "" ' name $8. +3 format $ ' "" ' name $8. +3 format $ ' "
'; run; * clean up by removing temporary files, datasets and filename pointers. ; x 'del temp00.sas'; proc datasets ddname=work nolist; delete var; quit; %end; %else %do; %put Note: Dataset &sdsetnam was not found or had no observations; %end; %mend;