<?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: Combine multiple RTF files to one file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/833939#M329704</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the macro on one scenario and found the page number&lt;STRONG&gt; did not keep the original one.&amp;nbsp;&lt;/STRONG&gt;Instead pages is from 1 to N where N is the number of total pages of combined RTF file. The reason I suspect is that RTF code when opened in NotePad++ contains page information like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;\fldinst { PAGE }}}{ of }{\field{\*\fldinst { NUMPAGES }}}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;. And this is probably due to fact that RTF code "&lt;FONT color="#FF0000"&gt;^{pageof}&lt;/FONT&gt;" in used in proc report in SAS program to create the RTF file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help?&lt;/P&gt;</description>
    <pubDate>Sat, 17 Sep 2022 01:50:05 GMT</pubDate>
    <dc:creator>jsbyxws</dc:creator>
    <dc:date>2022-09-17T01:50:05Z</dc:date>
    <item>
      <title>Combine multiple RTF files to one file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807239#M318217</link>
      <description>&lt;P&gt;I am trying to combine multiple RTF files to one RTF file using the macro below. I ran the code below and creates blank RTF file and it is corrupted which could not be opened.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found the macro on this link:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://pharma-sas.com/a-sas-macro-to-combine-portrait-and-landscape-rtf-files-into-one-single-file/" target="_blank"&gt;http://pharma-sas.com/a-sas-macro-to-combine-portrait-and-landscape-rtf-files-into-one-single-file/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone take the code below if any issue?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or will be appreciated if any other macro is available.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro m_combrtf(inpath= ,outpath= ,outfile= );&lt;BR /&gt;*Get rtf file names from a folder;&lt;BR /&gt;data rtffiles(keep=fileloc fnm);&lt;BR /&gt;length fref $8 fnm $80 fileloc $400;&lt;/P&gt;&lt;P&gt;rc = filename(fref, "&amp;amp;inpath");&lt;BR /&gt;if rc = 0 then did = dopen(fref);&lt;/P&gt;&lt;P&gt;dnum = dnum(did);&lt;/P&gt;&lt;P&gt;do i = 1 to dnum;&lt;BR /&gt;fnm = dread(did, i);&lt;BR /&gt;fid = mopen(did, fnm);&lt;BR /&gt;if fid &amp;gt; 0 and index(fnm,'docx') then do;&lt;BR /&gt;fileloc="&amp;amp;inpath\"||left(trim(fnm));&lt;BR /&gt;fnm = strip(tranwrd(fnm,".docx",""));&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;rc = dclose(did);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*Sort rtf files by tfl number;&lt;BR /&gt;data rtffiles(keep= fileloc ord tflno);&lt;BR /&gt;length tflno $200 ;&lt;BR /&gt;set rtffiles;&lt;/P&gt;&lt;P&gt;if upcase(fnm)^="TOC" then do;&lt;BR /&gt;if substr(upcase(fnm),1,1)="T" then ord = 1;&lt;BR /&gt;else if substr(upcase(fnm),1,1)="F" then ord = 2;&lt;BR /&gt;else if substr(upcase(fnm),1,1)="L" then ord = 3;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;tflno = strip(tranwrd(fnm,".docx",""));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = rtffiles; by ord tflno; run;&lt;/P&gt;&lt;P&gt;*Create macro variable which contains all rtf files;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select quote(strip(fileloc)) into :rtffiles separated by ', '&lt;BR /&gt;from rtffiles;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;filename rtffiles (&amp;amp;rtffiles); * create filename rtffiles ###;&lt;BR /&gt;*Start;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select fileloc into :fileloc from rtffiles(obs = 1);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/*%put &amp;amp;fileloc;*/&lt;BR /&gt;/*%put &amp;amp;rtffiles;*/&lt;/P&gt;&lt;P&gt;data start;&lt;BR /&gt;length rtfcode $32767;&lt;BR /&gt;infile "&amp;amp;fileloc" lrecl = 32767 end = eof;&lt;BR /&gt;input ;&lt;BR /&gt;rtfcode = _infile_;&lt;/P&gt;&lt;P&gt;retain kpfl strfl;&lt;/P&gt;&lt;P&gt;if substr(rtfcode,1,6)='\sectd' then kpfl=1;&lt;BR /&gt;if index(rtfcode, "\paperw") and index(rtfcode,"\paperh") then delete;&lt;BR /&gt;if kpfl = . then output start;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*data rtf;&lt;BR /&gt;data rtf(keep = rtfcode);&lt;BR /&gt;length rtfcode $32767 tflnam $1000;&lt;BR /&gt;set rtffiles end=last;&lt;BR /&gt;sof+1;&lt;BR /&gt;retain kpfl ;&lt;/P&gt;&lt;P&gt;do until (eof);&lt;BR /&gt;infile rtffiles lrecl=32767 end=eof filevar=fileloc;&lt;BR /&gt;input;&lt;BR /&gt;rtfcode=_infile_;&lt;/P&gt;&lt;P&gt;*Remove RTF header section and replce \sectd with \pard\sect\sectd;&lt;BR /&gt;if sof then kpfl=.;&lt;BR /&gt;if substr(rtfcode,1,6)='\sectd' then do;&lt;BR /&gt;num+1;&lt;BR /&gt;kpfl=1;&lt;BR /&gt;if num = 1 then rtfcode=compress(tranwrd(rtfcode,'\pgnrestart\pgnstarts1',''));&lt;BR /&gt;else rtfcode='\pard\sect'||compress(tranwrd(rtfcode,'\pgnrestart\pgnstarts1',''));&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;*Remove RTF closing } except for last file;&lt;BR /&gt;if eof and not last then delete;&lt;/P&gt;&lt;P&gt;*output concatenated rtf;&lt;BR /&gt;if kpfl=1 then output rtf;&lt;/P&gt;&lt;P&gt;sof=0;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;file "&amp;amp;outpath\&amp;amp;outfile..docx" lrecl=32767 nopad;&lt;BR /&gt;set start rtf; *concatenate rtf header,document info, all rtf files;&lt;BR /&gt;put rtfcode;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend m_combrtf;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%m_combrtf(inpath = C:\Users\mh\Desktop\Macros\rtf files,&lt;BR /&gt;outpath = C:\Users\mh\Desktop\Macros\rtf files,&lt;BR /&gt;outfile = sample);&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 19:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807239#M318217</guid>
      <dc:creator>Semie</dc:creator>
      <dc:date>2022-04-11T19:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple RTF files to one file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807244#M318222</link>
      <description>&lt;P&gt;I would suggest reading some of those files one-at-a-time into a data set and then looking at them. There is that pesky Length limit on the variable you are using RTFCODE. A long paragraph could well exceed that, which means that you have the "start paragraph" RTF information but miss the "end paragraph".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have images in the file that is another issue that you may not have an object fit completely into a single variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I would use a word processing program to do such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are creating the RTF output then place all of in a single ODS RTF/ODS RTF close; statement OR look into Proc Document as a way to combine things created by SAS in a single session.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 20:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807244#M318222</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-11T20:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple RTF files to one file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807254#M318232</link>
      <description>Thank you so much for the suggestion.&lt;BR /&gt;&lt;BR /&gt;One of the files had image which caused the file to be corrupted and now working great.</description>
      <pubDate>Mon, 11 Apr 2022 22:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807254#M318232</guid>
      <dc:creator>Semie</dc:creator>
      <dc:date>2022-04-11T22:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple RTF files to one file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807454#M318362</link>
      <description>&lt;P&gt;One more question on the combining RTF files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an option to create TOC from the RTF files?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 18:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807454#M318362</guid>
      <dc:creator>Semie</dc:creator>
      <dc:date>2022-04-12T18:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple RTF files to one file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807483#M318373</link>
      <description>&lt;P&gt;If you open your RTF in a word processing application like MS Word then the answer is yes. SAS ODS can't post-process existing RTFs but can create TOCs if creating an RTF from scratch. Here's an &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p1vvsv8ucnjzjnn1wq5wrlp74mdb.htm#p0pg2tmkd9x2own1rsrokb83vcsy" target="_blank" rel="noopener"&gt;example&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 00:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/807483#M318373</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-04-13T00:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple RTF files to one file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/833939#M329704</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the macro on one scenario and found the page number&lt;STRONG&gt; did not keep the original one.&amp;nbsp;&lt;/STRONG&gt;Instead pages is from 1 to N where N is the number of total pages of combined RTF file. The reason I suspect is that RTF code when opened in NotePad++ contains page information like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;\fldinst { PAGE }}}{ of }{\field{\*\fldinst { NUMPAGES }}}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;. And this is probably due to fact that RTF code "&lt;FONT color="#FF0000"&gt;^{pageof}&lt;/FONT&gt;" in used in proc report in SAS program to create the RTF file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help?&lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2022 01:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-RTF-files-to-one-file/m-p/833939#M329704</guid>
      <dc:creator>jsbyxws</dc:creator>
      <dc:date>2022-09-17T01:50:05Z</dc:date>
    </item>
  </channel>
</rss>

