<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Escapechar and control characters not working in ODS WORD TOC in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923858#M26552</link>
    <description>&lt;P&gt;Unless you are dealing with 1000's of lines of code it is best to just paste the code into a text box opened on the forum with the &amp;lt;/&amp;gt; icon above the message window. That way no one has to download a file from an unknown source and we call all follow along:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;
*--- set outpout area ---;
%let output_area=&amp;lt;Insert path here&amp;gt;;

*--- Define the output tables ---;
%macro outputstuff(type=);

   ods proclabel="Table 1";
   proc print data=sashelp.class;
   run;
   ods &amp;amp;type. startpage=now;
   ods proclabel="Table 2";
   proc print data=sashelp.class;
   run;
   ods &amp;amp;type. startpage=now;
   ods proclabel="Table 3";
   proc print data=sashelp.class;
   run;

%mend outputstuff;


*---------*
| ODS RTF |
*---------*;
 
*--- Change title of TOC ---;
proc template;
   define style styles.test_rtf;
      parent=styles.rtf;
      style ContentTitle from ContentTitle /
         pretext = ""
         posttext="Line1(*ESC*){newline}Line2"
         color = dark blue
         ;
      end;
run;

*--- Generate output ---;
ods rtf file="&amp;amp;output_area./sas_bug.rtf"
        contents toc_data
        style=styles.test_rtf;

   %outputstuff(type=rtf);

ods rtf close;


*----------*
| ODS WORD |
*----------*;

*--- Change title of TOC ---;
data _null;
*call symputx('testtitle', catx('0A'x, "Line1", "Line2"));
call symputx('testtitle', "Line1(*ESC*){newline}Line2");
*call symputx('testtitle', "Line1\nLine2");

run;

proc template;
   define style styles.test_docx;
      parent=styles.word;
    style ContentTitle from ContentTitle /
         content = "&amp;amp;testtitle." 
         /*protectspecialcharacters=on*/ 
         /*asis=on*/
         /*contenttype="text/plain"*/
         ;
      end;
run;

*--- Generate output ---;
ods word file="&amp;amp;output_area./sas_bug.docx"
         options(contents="on" toc_data="on")
         style=styles.test_docx;

   %outputstuff(type=word);

ods word close;

&lt;/PRE&gt;
&lt;P&gt;Unless there is more manipulation involved you should consider using a %let instead of data _null_.&lt;/P&gt;
&lt;PRE&gt;%let testtitle=Line1(*ESC*){newline}Line2;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May want to use Proc template to look closely at the Styles.word.&lt;/P&gt;
&lt;P&gt;In my install it doesn't inherit much from Styles.default ( through Printer )as the Styles.RTF does. Which is likely why what works with RTF doesn't with Word, the "parent" values aren't there to modify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus my install still shows ODS Word as "preproduction", which sometimes means all the features aren't quite stable yet. I know that I can't get Word to render lots of tables correctly that have no problems in RTF (or PDF or HTML)&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2024 19:38:30 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-04-10T19:38:30Z</dc:date>
    <item>
      <title>Escapechar and control characters not working in ODS WORD TOC</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923839#M26551</link>
      <description>&lt;P&gt;I have been creating a macro that creates some ODS output along with a Table of Contents.&lt;/P&gt;
&lt;P&gt;My macro has a switch that allows users to select RTF, PDF or Word output (there are reasons for having the option of RTF and DOCX separately).&lt;/P&gt;
&lt;P&gt;The macro has an option to insert custom text for the TOC title line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i'm using ODS RTF I can manipulate the template style I am using and change the title within ContentTitle:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;style ContentTitle from ContentTitle /
  pretext = ""
  posttext="Line1(*ESC*){newline}Line2"
  color = dark blue;&lt;/PRE&gt;
&lt;P&gt;Notice I want multiple lines in the title, so i use the ODS escape command {newline}.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when I try and do the same for ODS WORD, no formatting is honored&lt;/P&gt;
&lt;P&gt;I have tried the following (creating the string as a macro variable to insert into the template):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null;
*call symputx('testtitle', catx('0A'x, "Line1", "Line2"));
call symputx('testtitle', "Line1(*ESC*){newline}Line2");
*call symputx('testtitle', "Line1\nLine2");
run;

proc template;
   define style styles.test_docx;
      parent=styles.word;
      style ContentTitle from ContentTitle /
         content = "&amp;amp;testtitle." 
         /*protectspecialcharacters=on*/ 
         /*asis=on*/
         /*contenttype="text/plain"*/
         ;
      end;
run;
&lt;/PRE&gt;
&lt;P&gt;ODS Escape sequences did not work, neither did ASCII like break characters or the simple "\n" (which weirdly printed out as "&lt;SPAN&gt;¥n"). I tried some other options I dug out of the log, like "protectspecialchars", "asis", etc but nothing seems to want to make a line break in an ODS WORD TOC.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does anyone have a solution before I contact the Technical guys?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Full testing program attached.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 16:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923839#M26551</guid>
      <dc:creator>nevla</dc:creator>
      <dc:date>2024-04-10T16:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Escapechar and control characters not working in ODS WORD TOC</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923858#M26552</link>
      <description>&lt;P&gt;Unless you are dealing with 1000's of lines of code it is best to just paste the code into a text box opened on the forum with the &amp;lt;/&amp;gt; icon above the message window. That way no one has to download a file from an unknown source and we call all follow along:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;
*--- set outpout area ---;
%let output_area=&amp;lt;Insert path here&amp;gt;;

*--- Define the output tables ---;
%macro outputstuff(type=);

   ods proclabel="Table 1";
   proc print data=sashelp.class;
   run;
   ods &amp;amp;type. startpage=now;
   ods proclabel="Table 2";
   proc print data=sashelp.class;
   run;
   ods &amp;amp;type. startpage=now;
   ods proclabel="Table 3";
   proc print data=sashelp.class;
   run;

%mend outputstuff;


*---------*
| ODS RTF |
*---------*;
 
*--- Change title of TOC ---;
proc template;
   define style styles.test_rtf;
      parent=styles.rtf;
      style ContentTitle from ContentTitle /
         pretext = ""
         posttext="Line1(*ESC*){newline}Line2"
         color = dark blue
         ;
      end;
run;

*--- Generate output ---;
ods rtf file="&amp;amp;output_area./sas_bug.rtf"
        contents toc_data
        style=styles.test_rtf;

   %outputstuff(type=rtf);

ods rtf close;


*----------*
| ODS WORD |
*----------*;

*--- Change title of TOC ---;
data _null;
*call symputx('testtitle', catx('0A'x, "Line1", "Line2"));
call symputx('testtitle', "Line1(*ESC*){newline}Line2");
*call symputx('testtitle', "Line1\nLine2");

run;

proc template;
   define style styles.test_docx;
      parent=styles.word;
    style ContentTitle from ContentTitle /
         content = "&amp;amp;testtitle." 
         /*protectspecialcharacters=on*/ 
         /*asis=on*/
         /*contenttype="text/plain"*/
         ;
      end;
run;

*--- Generate output ---;
ods word file="&amp;amp;output_area./sas_bug.docx"
         options(contents="on" toc_data="on")
         style=styles.test_docx;

   %outputstuff(type=word);

ods word close;

&lt;/PRE&gt;
&lt;P&gt;Unless there is more manipulation involved you should consider using a %let instead of data _null_.&lt;/P&gt;
&lt;PRE&gt;%let testtitle=Line1(*ESC*){newline}Line2;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May want to use Proc template to look closely at the Styles.word.&lt;/P&gt;
&lt;P&gt;In my install it doesn't inherit much from Styles.default ( through Printer )as the Styles.RTF does. Which is likely why what works with RTF doesn't with Word, the "parent" values aren't there to modify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus my install still shows ODS Word as "preproduction", which sometimes means all the features aren't quite stable yet. I know that I can't get Word to render lots of tables correctly that have no problems in RTF (or PDF or HTML)&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 19:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923858#M26552</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-10T19:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Escapechar and control characters not working in ODS WORD TOC</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923930#M26556</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;, I wasn't sure of the etiquette when wishing to post a program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the %let over a symputx – I did it like that so I could construct test strings using catx (like the included one where I was trying to insert an ascii ‘0A’x which i dodn't know would work in a %let). I haven't tried the byte function yet, but suspect it may have the same effect (but i'll try that now!)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for the PROC TEMPLATE, I have deconstructed all the styles in the past, and indeed built new ones entirely from scratch with no inheritance. What I couldn’t find in any of them, and indeed in any manual, is the right command that would trigger a line break within an ODS Word TOC title.&lt;/P&gt;
&lt;P&gt;And it is a little frustrating that ODS WORD is still preproduction after over 5 years but it is odd it doesn’t seems to conform to the usual ODS commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Worst case scenario is I do post-processing on the DOCX to insert a line break where I want, but that’s like cracking a walnut with a hammer – I’d rather find a simpler, more elegant solution &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 06:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923930#M26556</guid>
      <dc:creator>nevla</dc:creator>
      <dc:date>2024-04-11T06:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Escapechar and control characters not working in ODS WORD TOC</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923945#M26557</link>
      <description>&lt;P&gt;Solved!&lt;/P&gt;
&lt;P&gt;I had exhausted all the SAS tricks I knew, and focussed instead on manipulating the underlying XML of the resulting DOCX file.&lt;/P&gt;
&lt;P&gt;After experimenting with several possible solutions, I discovered that the title that you set in the ODS template is written &lt;STRONG&gt;directly to the WORD XML&lt;/STRONG&gt;, with &lt;STRONG&gt;no&lt;/STRONG&gt; interpretation at all.&lt;/P&gt;
&lt;P&gt;Line breaks are ignored because they have no meaning in XML, and so to insert a line break I had to use WORD XML languate instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc template;
  define style styles.test_docx;
    parent=styles.word;
      style ContentTitle from ContentTitle /
        content = "Title1&amp;lt;w:br /&amp;gt;Title2" ;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So I can add something to substutute "&lt;STRONG&gt;(*ESC*){newline}&lt;/STRONG&gt;" with&amp;nbsp;"&lt;STRONG&gt;&amp;lt;w:br /&amp;gt;"&lt;/STRONG&gt;&amp;nbsp;in the input parameters, or use some keyword a user can specify to mean a line break that i replace as required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 10:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Escapechar-and-control-characters-not-working-in-ODS-WORD-TOC/m-p/923945#M26557</guid>
      <dc:creator>nevla</dc:creator>
      <dc:date>2024-04-11T10:13:08Z</dc:date>
    </item>
  </channel>
</rss>

