The SAS Output Delivery System and reporting techniques

Format is changed when data _null_ and file are used to output

Posts: 41

Format is changed when data _null_ and file are used to output

[ Edited ]

Hi SAS experts,


I'm trying to write a macro to do 1. compile files 2. add TOC.

Attched files are needed to run the program as below. Two issues:

1. Font for L16.2.6.4 and L16.2.6.5 is courier new with 8pt. But when they are combined, it changed to time new roman automatically, please see complied.rtf.

2. Is there any way that can make TOC portrait and L16.2.6.4 & L16.2.6.5 landscape.


Thank you very much!


proc template;
    define style styles.ftoc;
    style body from document /

options orientation=portrait;
*This creates the Table of Contents RTF file;
ods listing close;
ods rtf file="&loc.\TOC.rtf" style=ftoc headery = 500 footery = 500 startpage=no anchor='TOC';
proc report data=text2 nowd missing    

    style(column)={asis=on font_size=10pt font_face="Courier New" font_weight=bold
                            background=white  foreground=black  /*cellheight=0.4in*/}
    style(header)={asis=on just=left font_size=12pt font_face="Courier New" font_weight=bold
                            background=white  foreground=black  bordertopcolor=black
                            borderbottomcolor=black bordertopwidth=1 borderbottomwidth=1 }
    style(lines)={asis=on just=left font_size=10pt font_face="Courier New" font_weight=bold
                            background=white  foreground=black};
    column ttlord fdisp;
    define ttlord/order order=internal noprint;
    define fdisp / "Table of Contents";

ods rtf close;
ods listing;

%Macro Compile(titles=toc2);

*Step 1: Read in the TOC file and modify the end RTF code;
data readtoc;
    infile "&loc.\TOC.rtf" missover length=len end=fin
        lrecl=2000 firstobs=1;
    input string $varying2000. len;
    if fin then do;
        string=compress(string,'}'); *The final } ends the RTF document, so it is removed
            to add additional code (i.e. RTF documents.;
run; quit;

*Step 2: Begin Compiled file;
data _null_;
    file "&loc.\Compiled.rtf" lrecl=2000;
    set readtoc;
    put string;

*Step 3: Read in tables from the titles dataset and create macro variables;
data _null_;
    set &titles. end=fin;
    if anatype='Table' then call symput('F'||strip(_n_),'T'||strip(FINALNO));
    else if anatype='Listing' then call symput('F'||strip(_n_),'L'||strip(FINALNO));
    if fin then call symput('fileno',strip(_n_));

*Step 4: Read in each table file and modify the RTF code;
%do tt=1 %to &fileno.;
    %put &&F&tt..;

data readrtf;
    infile "&loc.\&&F&tt...rtf" missover length=len end=fin
        lrecl=2000 firstobs=25; *This starts at 25, because the first 24 lines of code
            are for document creation and are included in the TOC section.;
    input string $varying2000. len;

    if _n_=1 then string="\sect"||strip(string); *The \sect creates a break and a new
        section at the beginning of this table.;
    else string=string;

    if fin then do;

    *Change bookmark name on 1st page;
    if find(string,'*\bkmkstart IDX}{\*\bkmkend IDX}')>0 then do;
    *Remove other bookmarks;
    else if find(string,'\bkmkstart')>0 then do;
        rstart=find(string,'\bkmkstart'); *Find the position of \bkmkstart;
        bkmk=scan(substr(string,rstart),2,' }{\'); *Find the name of the bookmark (2nd word);
        bkmkend=find(string,'\bkmkend'); *Find the position of \bkmkend;
        rend=find(string, strip(bkmk), bkmkend)+length(bkmk)-1; *Find the position of the bookmark after \bkmrkend plus the length of the bookmark name;
        remove=substr(string,rstart,(rend-rstart+1)); *String to be removed;
        string=tranwrd(string,strip(remove),''); *Remove bookmark RTF code;

*Step 4a: Write to RTF file;
data _null_;
        file "&loc.\Compiled.rtf" lrecl=2000 mod;
    set readrtf;
    put string;


*Step 5: Finish RTF file;
data _null_;
        file "&loc.\Compiled.rtf" lrecl=32767 mod;
    put '}';

%Mend Compile;


Posts: 41

Re: Format is changed when data _null_ and file are used to output

Posted in reply to fbl204653
Posts: 9,364

Re: Format is changed when data _null_ and file are used to output

Posted in reply to fbl204653

Hi, I have not read the paper you referenced and I hardly ever use DATA step with RTF. So this might end up to be a question for Tech Support. However, if I use "vanilla" RTF with the orientation controls, as shown below, I am able to get TOC in portrait and the SASHELP.CARS output in landscape.


  Code and output shown in image of first 2 pages in Print Preview.





Posts: 41

Re: Format is changed when data _null_ and file are used to output

Posted in reply to Cynthia_sas

Thanks for your reply, Cynthia! I used Infile statement to read the attached file that was generated using 'ods rtf', then I tried to use 'ods rtf' like you suggested to output it. The rtf files turns out to be like the snap as below. data _null_+file statement is the only method I tried that is able to generate the right output. Is there an other output method. Thanks again for your help!



Ask a Question
Discussion stats
  • 3 replies
  • 2 in conversation