BookmarkSubscribeRSS Feed
fbl204653
Obsidian | Level 7

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!

Bob


proc template;
    define style styles.ftoc;
    parent=styles.rtf;
    style body from document /
        leftmargin=1in
        rightmargin=1in
        topmargin=1.25in
        bottommargin=1in;
    end;
run;

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';
title;
footnote;
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";

run;
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.;
    end;
run; quit;


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


*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_));
run;

*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;
        string=compress(string,'}');
    end;

    *Change bookmark name on 1st page;
    if find(string,'*\bkmkstart IDX}{\*\bkmkend IDX}')>0 then do;
        string=tranwrd(string,'IDX',strip(translate("&&F&tt..",'_','.')));
    end;
    *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;
    end;
run;

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

%end;

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

%Mend Compile;

%Compile;

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

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.

 

cynthia

 

regular_switch_orientation.png

fbl204653
Obsidian | Level 7

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!

 

Capture.PNG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1253 views
  • 0 likes
  • 2 in conversation