%macro out2htm(htmlfile=,
      htmlfref=,
      openmode=replace,
      runmode=B,
      encode=Y,
      catname=,
      proploc=,
      capture=,
      window=OUTPUT,
      bgtype=,
      bg=,
      septype=,
      seploc=,
      saspower=,
      brtitle=,
      center=,
      ctext=,
      tcolor=,
      fcolor=,
      bcolor=,
      hcolor=,
      ncolor=,
      wcolor=,
      ecolor=,
      scolor=,
      dcolor=,
      tface=,
      fface=,
      bface=,
      hface=,
      nface=,
      wface=,
      eface=,
      sface=,
      dface=,
      tsize=,
      fsize=,
      bsize=,
      hsize=,
      nsize=,
      wsize=,
      esize=,
      ssize=,
      dsize=,
      ttag=,
      ftag=,
      btag=,
      htag=,
      ntag=,
      wtag=,
      etag=,
      stag=,
      dtag=);

%*********************************************************************;
%*                       *;
%*  MACRO: OUT2HTM --  EXPERIMENTAL  --          *;
%*                       *;
%*  USAGE: %out2htm(arg1=value, arg2=value, ... argN=valueN);    *;
%*                       *;
%*  DESCRIPTION:                   *;
%*  Experimental Software              *;
%*  This macro captures SAS procedure output, formats it as HTML,  *;
%*  and stores the resulting HTML code in an external file.    *;
%*                       *;
%*  NOTES:                     *;
%*  None.                    *;
%*                       *;
%*  SUPPORT: sasvcd                  *;
%*                       *;
%*  VERSION: 1.0                   *;
%*                       *;
%*********************************************************************;

%local htmlfile htmlfref openmode runmode catname proploc
   capture window bgtype bg septype seploc center
   ctext tcolor fcolor bcolor hcolor ncolor wcolor ecolor scolor
   cdata tface fface bface hface nface wface eface sface
   dface tsize fsize bsize hsize nsize wsize esize ssize
   dsize htitle hfoot hby hhead hnote hwarn herror hsource
   hdata notes eflag encode saspower brtitle;

%*global _proploc;

%let notes=%sysfunc(getoption(notes));

options nonotes;

%if &sysver lt 6.11 %then %do;
  %put;
  %put ERROR: The Output Generator is not supported prior to release 6.11.;
  %put;
  %goto exit;
%end;

 /********************************************************
%if "&catname" eq ""
  %then %let catname=work._htmlg_._temp1_.output;
 ********************************************************/

%if "&runmode" eq "" %then %do;
  %put;
  %put ERROR: You must specify either I, B or S for execution mode.;
  %put;
  %goto exit;
%end;

%if (%upcase(&runmode) ne B) and
  (%upcase(&runmode) ne S) and
  (%upcase(&runmode) ne I)
%then %do;
  %put;
  %put ERROR: &runmode is an unknown or unsupported execution mode.;
  %put %str(   Specify either I, B or S.);
  %put;
  %goto exit;
%end;

%if ("&capture" eq "") and
  (%upcase(&runmode) eq B or %upcase(&runmode) eq S)
%then %do;
  %put;
  %put ERROR: You must specify either ON or OFF for the CAPTURE argument.;
  %put;
  %goto exit;
%end;

%if ((%upcase(&capture) ne OFF) and
   (%upcase(&capture) ne ON)) and
  (%upcase(&runmode) eq B or %upcase(&runmode) eq S)
%then %do;
  %put;
  %put ERROR: &capture is an unknown or unsupported CAPTURE value.;
  %put %str(   Specify either ON or OFF.);
  %put;
  %goto exit;
%end;

%if "&window" eq ""  %then %do;
  %put;
  %put ERROR: You must specify either OUTPUT or LOG for the WINDOW argument.;
  %put;
  %goto exit;
%end;
%if (%upcase(&window) ne OUTPUT) and
  (%upcase(&window) ne LOG)
%then %do;
  %put;
  %put ERROR: &window is an unknown or unsupported WINDOW value.;
  %put %str(   Specify either OUTPUT or LOG.);
  %put;
  %goto exit;
%end;

%if (%upcase(&window) eq OUTPUT) and
  ("&catname" eq "")
%then %then %let catname=work._htmlg_._temp1_.output;
%else %if (%upcase(&window) eq LOG) and
  ("&catname" eq "")
%then %then %let catname=work._htmlg_._temp1_.log;

%if ((%upcase(&capture) eq ON) and
   (%upcase(&runmode) eq B or %upcase(&runmode) eq S))
%then %do;
  %if (%upcase(&window) eq OUTPUT)
  %then %do;
  proc printto print=&catname new; run; quit;
  %put;
  %put NOTE: Capture of procedure output started.;
  %put;
  %end;
  %else %if (%upcase(&window) eq LOG)
  %then %do;
  proc printto log=&catname new; run; quit;
  %put;
  %put NOTE: Capture of log output started.;
  %put;
  %end;

  %goto exit;
%end;

%if ("&htmlfile" eq "") and
  (%upcase(&runmode) eq B or %upcase(&runmode) eq S) and
  ("&htmlfref" eq "")
%then %do;
  %put;
  %put ERROR: You must specify a file for the HTML output.;
  %put;
  %goto exit;
%end;

%if ("&htmlfile" ne "") and
  ("&htmlfref" ne "") and
  (%upcase(&runmode) eq B or %upcase(&runmode) eq S)
%then %do;
  %put;
  %put ERROR: You must specify a file OR fileref for the HTML output.;
  %put;
  %goto exit;
%end;

%if ("&openmode" eq "") and
  ("&htmlfile" ne "")
%then %do;
  %put;
  %put ERROR: You must specify a mode for opening the HTML output file.;
  %put;
  %goto exit;
%end;

%if (%upcase(&openmode) ne REPLACE) and
  (%upcase(&openmode) ne APPEND)  and
  ("&htmlfile" ne "")
%then %do;
  %put;
  %put ERROR: &openmode is an unknown or unsupported open mode.;
  %put %str(   Specify either REPLACE or APPEND.);
  %put;
  %goto exit;
%end;

 /******  not needed

%if "&catname" eq "" %then %do;
  %put;
  %put ERROR: You must specify the 4-level name of the catalog entry;
  %put %str(   that contains that SAS output to be formatted.);
  %put;
  %goto exit;
%end;
 **********************/

 /*****************************************************************

%if ("&bgcolor" ne "") and
  ("&bg"  ne "")
%then %do;
  %put;
  %put ERROR: Both background and background color were specified. Only;
  %put %str(   one specification is allowed.);
  %put;
  %goto exit;
%end;

 *****************************************************************/

%if ("&bgtype" ne "")     and
  (%upcase(&bgtype) ne NONE)  and
  (%upcase(&bgtype) ne COLOR) and
  (%upcase(&bgtype) ne IMAGE)
%then %do;
  %put;
  %put ERROR: &bgtype is an invalid value for background type.;
  %put %str(   Specify NONE, COLOR or IMAGE.);
  %put;
  %goto exit;
%end;

%if ("&bgtype" eq "") and
  ("&bg"   ne "")
%then %do;
  %put;
  %put ERROR: You must specify a background type.;
  %put;
  %goto exit;
%end;

%if (%upcase(&bgtype) eq IMAGE) and
  ("&bg" eq "")
%then %do;
  %put;
  %put ERROR: You must specify an image location for the background.;
  %put;
  %goto exit;
%end;

%if (%upcase(&bgtype) eq COLOR) and
  ("&bg" eq "")
%then %do;
  %put;
  %put ERROR: You must specify a color for the background.;
  %put;
  %goto exit;
%end;

%if ("&septype" ne "")     and
  (%upcase(&septype) ne NONE)  and
  (%upcase(&septype) ne RULE)  and
  (%upcase(&septype) ne IMAGE)
%then %do;
  %put;
  %put ERROR: &septype is an invalid value for page break separator.;
  %put %str(   Specify NONE, RULE or IMAGE.);
  %put;
  %goto exit;
%end;

%if ("&septype" ne "")     and
  (%upcase(&septype) ne NONE)  and
  (%upcase(&septype) ne RULE)  and
  (%upcase(&septype) ne IMAGE)
%then %do;
  %put;
  %put ERROR: &septype is an invalid value for page break separator.;
  %put %str(   Specify NONE, RULE or IMAGE.);
  %put;
  %goto exit;
%end;

%if (%upcase(&septype) eq IMAGE) and
  ("&seploc" eq "")
%then %do;
  %put;
  %put ERROR: You must specify an image location for the page break separator.;
  %put;
  %goto exit;
%end;

%if ("&septype" eq "") and
  ("&seploc"  ne "")
%then %let septype = Image;

%*;
%*  Check the syntax of the 4-level name. Existence will be handled
%*  in the SCL code.
%*;

%if "&proploc" ne "" %then %do;

  %if %length(%scan(&proploc, 1, '.')) gt 8 %then %do;
  %put;
  %put ERROR: &proploc is an invalid 4-level name for the SLIST entry;
  %put %str(   that contains the properties.);
  %put;
  %goto exit;
  %end;

  %if (%length(%scan(&proploc, 2, '.')) gt 8) or
  (%length(%scan(&proploc, 2, '.')) eq 0)
  %then %do;
  %put;
  %put ERROR: &proploc is an invalid 4-level name for the SLIST entry;
  %put %str(   that contains the properties.);
  %put;
  %goto exit;
  %end;

  %if (%length(%scan(&proploc, 3, '.')) gt 8) or
  (%length(%scan(&proploc, 3, '.')) eq 0)
  %then %do;
  %put;
  %put ERROR: &proploc is an invalid 4-level name for the SLIST entry;
  %put %str(   that contains the properties.);
  %put;
  %goto exit;
  %end;

  %if (%upcase(%scan(&proploc, 4, '.')) ne SLIST)
  %then %do;
  %put;
  %put ERROR: &proploc is an invalid 4-level name for the SLIST entry;
  %put %str(   that contains the properties.);
  %put;
  %goto exit;
  %end;

%end;

%*let _proploc=&proploc;

%if "&encode" eq "" %then %do;
  %put;
  %put ERROR: You must specify either Y, or N for the ENCODE argument.;
  %put;
  %goto exit;
%end;

%if (%upcase(&encode) ne Y) and
  (%upcase(&encode) ne N) and
  (%upcase(&encode) ne YES) and
  (%upcase(&encode) ne NO)
%then %do;
  %put;
  %put ERROR: &encode is an unknown or unsupported ENCODE value.;
  %put %str(   Specify either Y or N.);
  %put;
  %goto exit;
%end;

%if &encode ne
%then %let encode=%upcase(%substr(&encode, 1, 1));

%if (%upcase(&center) ne Y) and
  (%upcase(&center) ne N) and
  (%upcase(&center) ne YES) and
  (%upcase(&center) ne NO) and
  (%upcase(&center) ne  )
%then %do;
  %put;
  %put ERROR: &center is an unknown or unsupported CENTER value.;
  %put %str(   Specify either Y or N.);
  %put;
  %goto exit;
%end;

%if &center ne
%then %let center=%upcase(%substr(&center, 1, 1));

%if (%upcase(&runmode) eq B or %upcase(&runmode) eq S) %then %do;

  %if "&window" eq ""  %then %do;
  %put;
  %put ERROR: You must specify either OUTPUT or LOG for the WINDOW argument.;
  %put;
  %goto exit;
  %end;
  %if (%upcase(&window) ne OUTPUT) and
  (%upcase(&window) ne LOG)
  %then %do;
  %put;
  %put ERROR: &window is an unknown or unsupported WINDOW value.;
  %put %str(   Specify either OUTPUT or LOG.);
  %put;
  %goto exit;
  %end;

  %if (%upcase(&window) eq OUTPUT)
  %then %do;
  %*if "&catname" eq ""
  %*then %let catname=work._htmlg_._temp1_.output;
  proc printto print=print; run; quit;
  %end;
  %else %if (%upcase(&window) eq LOG)
  %then %do;
  %*if "&catname" eq ""
  %*then %let catname=work._htmlg_._temp1_.log;
  proc printto log=log; run; quit;
  %end;

 /**************************************************************
  %if &sysver lt 6.12 %then %do;
  proc display c=sashelp.htmlgen.outgenx.scl; run;
  %end;
  %else %do;
 **************************************************************/
  proc display c=sashelp.htmlgen.outgenb.scl; run;
  %*end;
  %put;
  %put NOTE: Capture of output finished.;
  %put;
%end;
%else %do;
  %if ("&htmlfile" ne "") and
  ("&openmode" ne "") and
  ("&window" ne "")
  %then %do;
  dm "next &window ; save &catname replace";
 /**************************************************************
  %if &sysver lt 6.12 %then %do;
  proc display c=sashelp.htmlgen.outgenx.scl; run;
  %end;
  %else %do;
 **************************************************************/
  proc display c=sashelp.htmlgen.outgenb.scl; run;
  %*end;
  %goto exit;
  %end;
  %else %do;
  %if "&sysver" lt "6.12" %then %do;
  %put;
  %put ERROR: Interactive mode not supported prior to release 6.12.;
  %put;
  %goto exit;
  %end;
  proc display c=sashelp.htmlgen.outgeni.frame; run;
  %goto exit;
  %end;
%end;

%exit:
%*let _proploc=;
options &notes;

%mend out2htm;
