Hi All,
can any one tell me how to write SAS HTML code for proc report for genrating ODS output
Regards,
Rajasekhar.B
You don't write HTML code.
You use ODS HTML (and the proper options) and then simply run your proc report. Then you use ODS HTML CLOSE to close the HTML destination.
Hi,
I want to debug below code , can any one help me how to understand below inforamtion
if _n_=1 then do;
put "MIME-Version: 1.0";
put "Content-Type: multipart/related; boundary=""----=_NextPart_01CC720C.7373BA80""";
put ;
put "------=_NextPart_01CC720C.7373BA80";
put "Content-Location: file:///C:/main-document.htm";
put "Content-Transfer-Encoding: quoted-printable";
put "Content-Type: text/html; charset=""us-ascii""";
put ;
put "<html xmlns:v=3D""urn:schemas-microsoft-com:vml""";
put "xmlns:o=3D""urn:schemas-microsoft-com:office:office""";
put "xmlns:w=3D""urn:schemas-microsoft-com:office:word""";
put "xmlns:m=3D""http://schemas.microsoft.com/office/2004/12/omml""";
put "xmlns=3D""http://www.w3.org/TR/REC-html40"">";
put ;
put '<head>';
/* document metadata */
put '<!--[if gte mso 9]>';
put ' <xml>';
put " <o:DocumentProperties>";
put " <o:Subject></o:Subject>";
put " <o:Author>&sysuserid</o:Author>";
put " <o:LastAuthor>&sysuserid</o:LastAuthor>";
put " <o:Created>%sysfunc(date(),yymmdd10.)T%sysfunc(time(),time8.)Z</o:Created>";
put " <o:LastSaved>%sysfunc(date(),yymmdd10.)T%sysfunc(time(),time8.)Z</o:LastSaved>";
put " <o:Category>clinical / statistical analysis</o:Category>";
put " </o:DocumentProperties>";
put " <o:CustomDocumentProperties>";
put " </o:CustomDocumentProperties>";
put " <w:WordDocument>";
put " <w:SpellingState>Clean</w:SpellingState>";
put " <w:GrammarState>Clean</w:GrammarState>";
put " <w:View>Print</w:View>";
put " </w:WordDocument>";
put ' </xml>';
put '<![endif]-->';
put '<![endif]-->';
put '</head>';
put '<body>';
put " <div class=3DWordSection1>";
%if %qupcase(&type)=NARRATIVE %then %do;
put " <h1>Table of Narratives</h1>";
%end;
%if %qupcase(&type)=PROFILE %then %do;
put " <h1>Table of Subject Profiles</h1>";
%end;
%if %qupcase(&type)=LISTING %then %do;
put " <h1>Table of Subject Data Listings</h1>";
%end;
end;
if _n_=1 then do;
put '<p> </p><table class=3DTOC width=3D"' "%sysevalf(%sysfunc(min(12,%sysevalf(84/&_selections)))*&_selections+16) " '%">';
end;
if first.subjid then do;
if missing(subjid) then do;
put "<thead><tr><th class=3DTOC width=3D""16%"">Narrative Subject Identifier<br>n=3D&_allNarratives</th>";
end;
else do;
put "<tr><td class=3DTOC>" '<a href=3D"#' usubjid +(-1) '">' subjid +(-1) '</a>' "</td>";
end;
end;
if missing(subjid) then do;
put "<th class=3DTOC width=3D""%sysfunc(min(12,%sysevalf(84/&_selections)))%"">" _text '<br>n=3D' _cntNarratives '</th>';
end;
else do;
if _nrQualifies
then put "<td class=3DTOC>X</td>";
else put '<td class=3DTOC> </td>';
end;
if last.subjid then do;
put '</tr>';
if missing(usubjid) then put '</thead><tbody>';
end;
if eof then do;
put '</tbody></table>';
put "<br clear=3Dall style=3D'mso-special-character:line-break;page-break-before:always'>";
%if %upcase(&document) ne ALL %then %do;
put ' </div>';
put ' </body>';
put '</html>';
put ;
put "------=_NextPart_01CC720C.7373BA80";
put "Content-Location: file:///C:/main-document-files/header.htm";
put "Content-Transfer-Encoding: quoted-printable";
put "Content-Type: text/html; charset=""us-ascii""";
put ;
put "<html xmlns:v=3D""urn:schemas-microsoft-com:vml""";
put "xmlns:o=3D""urn:schemas-microsoft-com:office:office""";
put "xmlns:w=3D""urn:schemas-microsoft-com:office:word""";
put "xmlns:m=3D""http://schemas.microsoft.com/office/2004/12/omml""";
put "xmlns=3D""http://www.w3.org/TR/REC-html40"">";
put "<body lang=3DEN-US>";
put "<div style=3D'mso-element:header' id=3Dh1>";
put "<p class=3DMsoHeader style=3D""text-align:right"">";
put "<span style=3D'mso-field-code:"" STYLEREF \0022Heading 1\0022 \\* =";
put "MERGEFORMAT ""'></span>";
put "</p>";
put "</div>";
put "<div style=3D'mso-element:footer' id=3Df1>";
put "<p style=3d'mso-border-top-alt:solid windowtext .25pt;'>" &footnote "</p>";
put "<p class=3DMsoHeader>Page <!--[if supportFields]><span style=3D'mso-element=";
put ':field-begin''></span>PAGE \* MERGEFORMAT <span style=3D''mso-element:field-end''>';
put "</span>";
put "of <!--[if supportFields]><span style=3D'mso-element=";
put ':field-begin''></span>NUMPAGES \# "0" \* MERGEFORMAT <span style=3D''mso-element:field-end''>';
put '</span> ■ ' "Creation Date %sysfunc(datetime(),datetime.)" ' ■ ';
put "Program: &_SASFILEPATH_";
put "</p>";
put "</div>";
put "</body>";
put "</html>";
put;
put "------=_NextPart_01CC720C.7373BA80--";
%end;
end;
run;
put "MIME-Version: 1.0";
put "Content-Type: multipart/related; boundary=""----=_NextPart_01CC720C.7373BA80""";
put ;
put "------=_NextPart_01CC720C.7373BA80";
put "Content-Location: file:///C:/main-document.htm";
put "Content-Transfer-Encoding: quoted-printable";
put "Content-Type: text/html; charset=""us-ascii""";
put ;
put "<html xmlns:v=3D""urn:schemas-microsoft-com:vml""";
put "xmlns:o=3D""urn:schemas-microsoft-com:office:office""";
put "xmlns:w=3D""urn:schemas-microsoft-com:office:word""";
put "xmlns:m=3D""http://schemas.microsoft.com/office/2004/12/omml""";
put "xmlns=3D""http://www.w3.org/TR/REC-html40"">";
put ;
put '<head>';
/* document metadata */
put '<!--[if gte mso 9]>';
put ' <xml>';
put " <o:DocumentProperties>";
put " <o:Subject></o:Subject>";
put " <o:Author>&sysuserid</o:Author>";
put " <o:LastAuthor>&sysuserid</o:LastAuthor>";
put " <o:Created>%sysfunc(date(),yymmdd10.)T%sysfunc(time(),time8.)Z</o:Created>";
put " <o:LastSaved>%sysfunc(date(),yymmdd10.)T%sysfunc(time(),time8.)Z</o:LastSaved>";
put " <o:Category>clinical / statistical analysis</o:Category>";
put " <o:Company>Tibotec BVBA</o:Company>";
put " </o:DocumentProperties>";
put " <o:CustomDocumentProperties>";
put " </o:CustomDocumentProperties>";
put " <w:WordDocument>";
put " <w:SpellingState>Clean</w:SpellingState>";
put " <w:GrammarState>Clean</w:GrammarState>";
put " <w:View>Print</w:View>";
put " </w:WordDocument>";
put ' </xml>';
put '<![endif]-->';
/* css stylesheet */
%nrstyle;
put '<![endif]-->';
put '</head>';
put '<body>';
put " <div class=3DWordSection1>";
end;
%end;
if first.usubjid then do;
_display + 1;
put "<h1 style=3D""margin-left:81pt;text-indent: -81pt;"">";
%if %qupcase(&type)=NARRATIVE %then %do;
put 'Narrative Display';
%end;
%if %qupcase(&type)=PROFILE %then %do;
put 'Patient Profile';
%end;
%if %qupcase(&type)=LISTING %then %do;
put 'Patient Listing';
%end;
put '<span style=3D''mso-field-code:"SEQ Table \\* ARABIC"''>' _display +(-1) ': </span>';
put '<a name=3D"' usubjid +(-1) '">Subject ' usubjid +(-1) @;
put '</a></h1>';
end;
if _module ne 'COMMENTS' then do;
select(_type);
when('SECTION HEADER') do;
put ' <h2>■ ';
put _text +(-1) @;
if _comments then do;
put '<a href=3D"#' _commentId +(-1) '"><sup> Comment ' _commentNo +(-1) '</sup></a>';
end;
put '</h2>';
_newSection=1;
end;
when('SELECTION')
do;
%if %qupcase(&type)=NARRATIVE %then %do;
if first.usubjid then do;
put ' <h2>■ ';
put 'REASON FOR NARRATIVE SELECTION';
put '</h2>';
put ' <p class=3Dselection>';
_newSection = 0;
end;
put _text;
if last.usubjid then do;
put ' </p>';
end;
else put '</p><p class=3Dselection>';
%end;
end;
when('NO DATA REPORTED') do;
put ' <p class=3Dselection>';
put _text +(-1) '</p>';
end;
when('LIST LABEL') do;
if _newSection then do;
if _columns=1 then do;
put ' <p class=3Dlist>';
end;
else do;
put '<table width=3D"100 %"><tr>';
end;
_newSection = 0;
end;
if _columns>1 then do;
if first._column then do;
put '<td style=3D"padding-right:6 pt">';
end;
end;
put '<span class=3DlistLabel>' _text +(-1) ':</span>';
end;
when('LIST DATA') do;
if _columns eq 1 then do;
if _newSection then do;
put ' <p class=3Dlist>';
_newSection = 0;
end;
if _text eq '<br>' then do;
put '<br>';
end;
else do;
put '<span class=3DlistData>' _text +(-1) '</span> ';
end;
if last._dsno then put ' </p>';
end;
else do;
if _newSection then do;
put ' <table width=3D"100 %"><tr>';
_newSection = 0;
end;
if first._column then do;
put '<td style=3D"padding-right:6pt">';
end;
put '<span class=3DlistData>' _text +(-1) '</span>';
if last._column then put ' </td>';
if last._dsno then put ' </tr></table>';
end;
end;
when('TABLE HEADER') do;
if first._lineno then do;
if _lineno=1 then put ' <table><thead>';
put ' <tr class=3Dtrhead>';
end;
if not last._lineno then do;
put ' <th class=3DfirstTH style=3D"text-align:'@;
end;
else do;
put ' <th class=3DlastTH style=3D"text-align:'@;
end;
if _vtype='C' then put 'left">';else put 'right">';
put '<p class=3Dindented>';
put _text +(-1);
put '</p>';
put '</th>';
if last._lineno then put ' </tr></thead><tbody>';
end;
when('TABLE DATA') do;
if first._lineno then do;
put ' <tr>';
if _comments then do;
_text=trim(_text)||'<a href=3D"#'||trim(_commentId)||'"><sup> Comment '||strip(vvalue(_commentNo))||'</sup></a>';
end;
end;
if not last._lineno then do;
put ' <td class=3DfirstTD style=3D"text-align:';
end;
else do;
put ' <td class=3DlastTD style=3D"text-align:';
end;
if _vtype='C' then put 'left">';else put 'right">';
put "<p class=3Dindented>";
put _text +(-1);
put "</p>";
put '</td>';
if last._lineno then do;
put ' </tr>';
if last._dsno then put ' </tbody></table>';
end;
end;
end;
if last._dsno and _footnote ne ' ' then do;
put '<p style=3D"margin-left:12pt;margin-top:4pt;font-size:9pt"><i>' _footnote '</i></p>';
end;
end;
else do;
if first._module then do;
put ' <h2>■ Comments</h2>';
put ' <table><thead><tr class=3Dtrhead>';
put ' <th class=3DfirstTH style=3D"text-align:right"><p class=3Dthpl>Comment #</p></th>';
put ' <th class=3DlastTH style=3D"text-align:left"><p class=3Dthpl>Comment</p></th>';
put ' </tr></thead><tbody>';
end;
put ' <tr>';
_dcommentno + 1;
put ' <td class3D=firstTH style3D="text-align:right"><a name=3D"' _commentId +(-1) '"></a>' _commentno '</td>';
put ' <td class=3DlastTH style=3D"text-align:left">' comments '</td>';
put ' </tr>';
if last._module then do;
put '</tbody>';
put '</table>';
end;
end;
if last.usubjid then do;
%if %qupcase(&type)=NARRATIVE %then %do;
put ' <h2>■ ';
put 'NARRATIVE TEXT</h2>';
put ' <p class=3Dselection>To be completed</p>';
%end;
if not last._outfile then put " <br clear=3Dall style=3D'mso-special-character:line-break;page-break-before:always'>";
end;
if last._outfile then do;
put ' </div>';
put ' </body>';
put '</html>';
put ;
put "------=_NextPart_01CC720C.7373BA80";
put "Content-Location: file:///C:/main-document-files/header.htm";
put "Content-Transfer-Encoding: quoted-printable";
put "Content-Type: text/html; charset=""us-ascii""";
put ;
put "<html xmlns:v=3D""urn:schemas-microsoft-com:vml""";
put "xmlns:o=3D""urn:schemas-microsoft-com:office:office""";
put "xmlns:w=3D""urn:schemas-microsoft-com:office:word""";
put "xmlns:m=3D""http://schemas.microsoft.com/office/2004/12/omml""";
put "xmlns=3D""http://www.w3.org/TR/REC-html40"">";
put "<body lang=3DEN-US>";
put "<div style=3D'mso-element:header' id=3Dh1>";
put "<p class=3DMsoHeader style=3D""text-align:right"">";
put "<span style=3D'mso-field-code:"" STYLEREF \0022Heading 1\0022 \\* =";
put "MERGEFORMAT ""'></span>";
put "</p>";
put "</div>";
put "<div style=3D'mso-element:footer' id=3Df1>";
put "<p style=3d'mso-border-top-alt:solid windowtext .25pt;'>" &footnote "</p>";
put "<p class=3DMsoHeader>Page <!--[if supportFields]><span style=3D'mso-element=";
put ':field-begin''></span>PAGE \* MERGEFORMAT <span style=3D''mso-element:field-end''>';
put "</span>";
put "of <!--[if supportFields]><span style=3D'mso-element=";
put ':field-begin''></span>NUMPAGES \# "0" \* MERGEFORMAT <span style=3D''mso-element:field-end''>';
put '</span> ■ ' "Creation Date %sysfunc(datetime(),datetime.)" ' ■ ';
put "Program: &_SASFILEPATH_";
put "</p>";
put "</div>";
put "</body>";
put "</html>";
put;
put "------=_NextPart_01CC720C.7373BA80--";
end;
run;
%end;
Regards,
Rajasekhar Reddy
This is not proc report, this is part of a data step that creates text output. In this case, it is used to create MIME/HTML/XML code "manually", without using SAS ODS or other helpers.
Since important parts of the code are missing (the start of the macro definition, for instance, and parts of the data step), it is not possible to thoroughly help you.
One thing that stands out is a run; statement right in between, followed immediately by another put; sequence. This can't work, as you need a new DATA statement after the step boundary caused by the run;
To further understand the code, one would also need the dataset that is used as base for the data step.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.