<?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: Replace text in RTF file adds unwanted spaces in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/244010#M15086</link>
    <description>Thank you very much, you made my day!</description>
    <pubDate>Sat, 16 Jan 2016 18:21:05 GMT</pubDate>
    <dc:creator>jb3</dc:creator>
    <dc:date>2016-01-16T18:21:05Z</dc:date>
    <item>
      <title>Replace text in RTF file adds unwanted spaces</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/243992#M15083</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I create a report using tagsets.rtf_sample in SAS 9.4 M2 on Windows. For easier formatting of the headers in Word, I later would like to strip the section breaks from the RTF file. To do this, I found some macros &lt;A href="http://www.lexjansen.com/wuss/2014/51_Final_Paper_PDF.pdf" target="_blank"&gt;here&lt;/A&gt;. The macros seem to work OK, but they add unwanted spaces to my RTF, which appear before the first letters of a paragraph. I suspect it has something to do with the way the rtf is read and/or written.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code below I create an RTF file, read it and write it out without replacing anything - and the spaces magically appear...! (see screenshot).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I get rid of the spaces? Any help is greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Jonas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;CODE class=" language-sas"&gt;goptions device=actximg;
options nodate nonumber papersize=A4;
options nocenter;
%let file="c:\test.rtf";
%let dest="c:\test_replaced.rtf";
ods tagsets.rtf_sample 
	file=&amp;amp;file.
	startpage=no
;

ods text='First Page';
ods text='Cars';
proc print data=sashelp.cars noobs;
	where Make='Infiniti';
	var make model;
run;
ods text='Class';
proc print data=sashelp.class noobs;
	where name='Alfred';
run;

ods tagsets.rtf_sample startpage=now;

ods text='Second page';
ods text='Cars';
proc print data=sashelp.cars noobs;
	where Make='Infiniti';
	var make model;
run;
ods text='Class';
proc print data=sashelp.class noobs;
	where name='Alfred';
run;

ods tagsets.rtf_sample close; 

%macro TestPut(source=, destination=);
	data temp;
		length line $1000;
		infile &amp;amp;source. length=lg lrecl=1000 end=eof;
		input @1 line $varying1000. lg;
	run;

	data _null_;
		set temp;
		file &amp;amp;destination. ls=1000;
		put line;
	run;
%mend TestPut;


%testput(source=&amp;amp;file., destination=&amp;amp;dest.);&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12198i73DBF9CCE739002C/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Spaces inserted.png" title="Spaces inserted.png" /&gt;</description>
      <pubDate>Sat, 16 Jan 2016 13:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/243992#M15083</guid>
      <dc:creator>jb3</dc:creator>
      <dc:date>2016-01-16T13:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Replace text in RTF file adds unwanted spaces</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/244004#M15084</link>
      <description>&lt;P&gt;Try using the $VARYING to write LINE. &amp;nbsp;Note the use of LENGTH&lt;STRONG&gt;N&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lg = lengthn(line);
put line $varying1000. lg;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Jan 2016 17:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/244004#M15084</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-01-16T17:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replace text in RTF file adds unwanted spaces</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/244007#M15085</link>
      <description>&lt;P&gt;EDIT: Oh dear, I realize that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;&amp;nbsp;was faster.&lt;/P&gt;
&lt;P&gt;EDIT 2: Lesson learned: Post a short answer quickly, add details later.&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;----------&lt;/P&gt;
&lt;P&gt;Original reply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Jonas,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest the following solution: Replace the line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put line;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in macro TestPut by the two lines&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lg=lengthn(line);
put line $varying1000. lg;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rationale: "put line;" performs what is called simple&amp;nbsp;&lt;EM&gt;list&lt;/EM&gt; output. In contrast, "put line $varying1000. lg;" performs&amp;nbsp;&lt;EM&gt;formatted&lt;/EM&gt; output, in this case using the $VARYING1000. format, which corresponds to the&amp;nbsp;&lt;SPAN&gt;$VARYING1000. &lt;EM&gt;in&lt;/EM&gt;format, which was used to read the source file. There are at least two differences between these two output styles:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;Missing values of character variable LINE (these are represented by single blanks, as you certainly know) are written as they are, i.e. as single blanks, by simple list output. Using formatted output with the $VARYING&lt;EM&gt;w&lt;/EM&gt;. format with a length value of &lt;STRONG&gt;lg=0&lt;/STRONG&gt;, however, they are written as null strings (i.e. actually not written at all). Thus you avoid the 19 blanks which were interspersed into your destination file test_replaced.rtf due to the simple list output. The LENGTHN function (unlike the&amp;nbsp;LENGTH function) returns a value of 0 if the argument is a single blank.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;Leading blanks (i.e. indentations) are preserved by formatted output with the $VARYING&lt;EM&gt;w&lt;/EM&gt;. format, but not by&amp;nbsp;list output, which would left align all written LINE values. (You may not have noticed this difference, because there happened to be no leading blanks in your source file.)&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 16 Jan 2016 17:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/244007#M15085</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-16T17:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replace text in RTF file adds unwanted spaces</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/244010#M15086</link>
      <description>Thank you very much, you made my day!</description>
      <pubDate>Sat, 16 Jan 2016 18:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Replace-text-in-RTF-file-adds-unwanted-spaces/m-p/244010#M15086</guid>
      <dc:creator>jb3</dc:creator>
      <dc:date>2016-01-16T18:21:05Z</dc:date>
    </item>
  </channel>
</rss>

