<?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: Macro to combine RTF files runs without errors but the output has one page only in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831493#M328586</link>
    <description>&lt;P&gt;%macro combine(pathin=, pathout=, fileout=);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;filename dirlist pipe "dir ""&amp;amp;pathin*.rtf"" /b ";&lt;/P&gt;
&lt;P&gt;data dirlist; &lt;BR /&gt;infile dirlist length=reclen ; &lt;BR /&gt;input filename_ $varying1024. reclen ; &lt;BR /&gt;if scan(filename_,2,'.') in ('rtf'); &lt;BR /&gt;path="&amp;amp;pathin"; &lt;BR /&gt;if filename_ ne "&amp;amp;fileout..rtf";&lt;BR /&gt;filename=strip(path)||'\'||strip(filename_); &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint; &lt;BR /&gt;select count(*) into:n from dirlist; &lt;BR /&gt;select filename into:file1-:file%cmpres(&amp;amp;n) from dirlist; &lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;data rtf;set _null_;run;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;filename rtf "&amp;amp;&amp;amp;file&amp;amp;i" ;&lt;/P&gt;
&lt;P&gt;data rtf&amp;amp;i;&lt;BR /&gt;infile rtf missover length = l end = lastobs lrecl = 2000;&lt;BR /&gt;input line $varying2000. l;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;i=1 %then %do;&lt;BR /&gt;data rtf&amp;amp;i;&lt;BR /&gt;set rtf&amp;amp;i end=eof;&lt;BR /&gt;if eof then line="\pard}}";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %if &amp;amp;i=&amp;amp;n %then %do;&lt;BR /&gt;data rtf&amp;amp;i;&lt;BR /&gt;set rtf&amp;amp;i end=eof;&lt;BR /&gt;if _n_&amp;gt;29;&lt;BR /&gt;if _n_=30 then line="\sect"||trim(left(line));&lt;BR /&gt;if eof then line=trim(left(line))||"%sysfunc(repeat(\pard,%eval(&amp;amp;n-1)))}";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %do;&lt;BR /&gt;data rtf&amp;amp;i;&lt;BR /&gt;set rtf&amp;amp;i end=eof;&lt;BR /&gt;if _n_&amp;gt;29;&lt;BR /&gt;if _n_=30 then line="\sect"||trim(left(line));&lt;BR /&gt;if eof then line="\pard}}";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;data rtf;set rtf rtf&amp;amp;i;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;filename rtf "&amp;amp;pathout.&amp;amp;fileout..rtf" ;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set rtf;&lt;BR /&gt;file rtf lrecl=2000;&lt;BR /&gt;put line;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2022 02:13:31 GMT</pubDate>
    <dc:creator>Kc2</dc:creator>
    <dc:date>2022-09-02T02:13:31Z</dc:date>
    <item>
      <title>Macro to combine RTF files runs without errors but the output has one page only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831475#M328572</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using a macro to combine RTF outputs. The macro runs without errors but the final file has only the first output.&lt;/P&gt;
&lt;P&gt;The intermediate RTF files look correct.&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;KC&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 19:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831475#M328572</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-09-01T19:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine RTF files runs without errors but the output has one page only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831479#M328575</link>
      <description>&lt;P&gt;NO code attached so have no clue as to what you did or why it may not have all the output expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally I would say combining already created RTF files is a Word processor program job due to the volume of non-data elements that are in a typical RTF file.&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;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3443"&gt;@Kc2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using a macro to combine RTF outputs. The macro runs without errors but the final file has only the first output.&lt;/P&gt;
&lt;P&gt;The intermediate RTF files look correct.&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;KC&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 20:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831479#M328575</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-01T20:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine RTF files runs without errors but the output has one page only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831493#M328586</link>
      <description>&lt;P&gt;%macro combine(pathin=, pathout=, fileout=);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;filename dirlist pipe "dir ""&amp;amp;pathin*.rtf"" /b ";&lt;/P&gt;
&lt;P&gt;data dirlist; &lt;BR /&gt;infile dirlist length=reclen ; &lt;BR /&gt;input filename_ $varying1024. reclen ; &lt;BR /&gt;if scan(filename_,2,'.') in ('rtf'); &lt;BR /&gt;path="&amp;amp;pathin"; &lt;BR /&gt;if filename_ ne "&amp;amp;fileout..rtf";&lt;BR /&gt;filename=strip(path)||'\'||strip(filename_); &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint; &lt;BR /&gt;select count(*) into:n from dirlist; &lt;BR /&gt;select filename into:file1-:file%cmpres(&amp;amp;n) from dirlist; &lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;data rtf;set _null_;run;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;filename rtf "&amp;amp;&amp;amp;file&amp;amp;i" ;&lt;/P&gt;
&lt;P&gt;data rtf&amp;amp;i;&lt;BR /&gt;infile rtf missover length = l end = lastobs lrecl = 2000;&lt;BR /&gt;input line $varying2000. l;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;i=1 %then %do;&lt;BR /&gt;data rtf&amp;amp;i;&lt;BR /&gt;set rtf&amp;amp;i end=eof;&lt;BR /&gt;if eof then line="\pard}}";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %if &amp;amp;i=&amp;amp;n %then %do;&lt;BR /&gt;data rtf&amp;amp;i;&lt;BR /&gt;set rtf&amp;amp;i end=eof;&lt;BR /&gt;if _n_&amp;gt;29;&lt;BR /&gt;if _n_=30 then line="\sect"||trim(left(line));&lt;BR /&gt;if eof then line=trim(left(line))||"%sysfunc(repeat(\pard,%eval(&amp;amp;n-1)))}";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %do;&lt;BR /&gt;data rtf&amp;amp;i;&lt;BR /&gt;set rtf&amp;amp;i end=eof;&lt;BR /&gt;if _n_&amp;gt;29;&lt;BR /&gt;if _n_=30 then line="\sect"||trim(left(line));&lt;BR /&gt;if eof then line="\pard}}";&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;data rtf;set rtf rtf&amp;amp;i;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;filename rtf "&amp;amp;pathout.&amp;amp;fileout..rtf" ;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set rtf;&lt;BR /&gt;file rtf lrecl=2000;&lt;BR /&gt;put line;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 02:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831493#M328586</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-09-02T02:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine RTF files runs without errors but the output has one page only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831502#M328595</link>
      <description>&lt;P&gt;First a generic comment about debugging macros. When a macro doesn't do what you expect you can set&lt;/P&gt;
&lt;PRE&gt;options mprint;&lt;/PRE&gt;
&lt;P&gt;and if you are using complex macro variable constructions, like the indirect reference &amp;amp;&amp;amp;file&amp;amp;i you may want the SYMBOLGEN option as well.&lt;/P&gt;
&lt;P&gt;Convoluted macro logic may call for the MLOGIC option.&lt;/P&gt;
&lt;P&gt;Then re-run your macro to read more details of the generated code in the Log. Plus any messages will be closer to the actual generated code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second: Habitual use of code with the same data set as the input and output sets such as&lt;/P&gt;
&lt;PRE&gt;         data rtf&amp;amp;i;
            set rtf&amp;amp;i end=eof;
            if eof then line="\pard}}";
         run;
&lt;/PRE&gt;
&lt;P&gt;Are extremely difficult to debug because the output set completely replaces in the input set. So you can't trace data related issues very well. Better to have a different name on the output side so you can see if the output matches what you expect for a given input at any given step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data set RTF only has one file's worth of content then look to whether any of the Rtf&amp;amp;i were actually created and what their content looks like. But keep in mind the warning about about input/output sets with the same name. You no longer have, with your existing code, any idea of what the original Rtf&amp;amp;i sets looked like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of sticking that N and File&amp;amp; information into macro variables with this step:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
select count(*) into:n from dirlist;
select filename into:file1-:file%cmpres(&amp;amp;n) from dirlist;
quit;&lt;/PRE&gt;
&lt;P&gt;You can use the Dirlist data set directly, testing the _n_ variable instead of &amp;amp;n, and either use PUT statements to write a .SAS program file that you can read and verify for accuracy before %include it for execution or use the CALL Execute statement to write statements direct to the macro execution buffer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am little concerned about use of Macro functions in data step code such as in the following. How carefully did you test this before including it?&lt;/P&gt;
&lt;PRE&gt;         data rtf&amp;amp;i;
            set rtf&amp;amp;i end=eof;
            if _n_&amp;gt;29;
            if _n_=30 then line="\sect"||trim(left(line));
            if eof then line=trim(left(line))||"%sysfunc(repeat(\pard,%eval(&amp;amp;n-1)))}";
         run;
&lt;/PRE&gt;
&lt;P&gt;If you look at this example you can see no macro functions required:&lt;/P&gt;
&lt;PRE&gt;%let n=3;

data example;
   length x $ 50;
   x='Sometext';
   x=strip(x)||repeat('\pard',&amp;amp;n-1);
run;&lt;/PRE&gt;
&lt;P&gt;Strip is equivalent to Trim(left(&amp;lt;text value&amp;gt;)) and has been around for like 20 years. And if you use the CAT functions such as CATS would not even be needed as CATS strips all the values involved.&lt;/P&gt;
&lt;PRE&gt;%let n=3;

data example;
   length x $ 50;
   x='Sometext';
   x=cats(x,repeat('\pard',&amp;amp;n-1) );
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 04:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-RTF-files-runs-without-errors-but-the-output/m-p/831502#M328595</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-02T04:56:05Z</dc:date>
    </item>
  </channel>
</rss>

