/******************************************************************************************** * Remarks: * Macro Parameters: plotnames: Req - Names of PNG files (without file extension) to be inserted * into the RTF table. Multiple PNGs should be delimited by a '|'. * plotpath: Req - path where PNG files are located. The default is &opath. * orient: Req - Orientation of the Word document (landscape or portrait) * The default is portrait. * title: Not Req - Text used for the 1st title. If left missing, the * program will look for the titles and footnotes in the titles * spreadsheet specified in the global macro variable RMTITLEFILE. * fileid: Not Req - This is the name of the RTF output file without * file extension. If left missing, the program name will be * used as the output file name. * foot1: Not Req - Text used for the 1st footnote * foot2: Not Req - Text used for the 2nd footnote * foot3: Not req - Text used for the 3rd footnote * foot4: Not req - Text used for the 4th footnote * foot5: Not req - Text used for the 5th footnote * foot6: Not req - Text used for the 6th footnote * foot7: Not req - Text used for the 7th footnote * foot8: Not req - Text used for the 8th footnote * foot9: Not req - Text used for the 9th footnote * foot10: Not req - Text used for the 10th footnote * foot11: Not req - Text used for the 11th footnote * foot12: Not req - Text used for the 12th footnote * foot13: Not req - Text used for the 13th footnote * foot14: Not req - Text used for the 14th footnote * foot15: Not req - Text used for the 15th footnote * foot16: Not req - Text used for the 16th footnote * foot17: Not req - Text used for the 17th footnote * foot18: Not req - Text used for the 18th footnote * foot19: Not req - Text used for the 19th footnote * foot20: Not req - Text used for the 20th footnote * * Macro Sample Call: %rmggengraph(plotnames = surv1|surv2|surv3); *********************************************************************************************/ %macro gengraph (plotnames = , plotpath = &opath, orient = portrait, fileid = , title = , foot1 = , foot2 = , foot3 = , foot4 = , foot5 = , foot6 = , foot7 = , foot8 = , foot9 = , foot10 = , foot11 = , foot12 = , foot13 = , foot14 = , foot15 = , foot16 = , foot17 = , foot18 = , foot19 = , foot20 = ); /******************************************************************************************** * Check that required parameters have been specified: *********************************************************************************************/ %if %superq(plotnames) = %then %do; %put; %put %str(USER WARNING: RMGGENGRAPH Macro Aborted. PLOTNAMES parameter has not been specified); %put; %return; %end; %if %superq(plotpath) = %then %do; %put; %put %str(USER WARNING: RMGGENGRAPH Macro Aborted. PLOTPATH parameter has not been specified); %put; %return; %end; %if &orient = %then %do; %put; %put %str(USER WARNING: RMGGENGRAPH Macro Aborted. ORIENT parameter has not been specified); %put; %return; %end; /******************************************************************************************** * Identify the plots to be inserted into the RTF document: *********************************************************************************************/ %local n_plots i; %let plotnames = %sysfunc(compbl(&plotnames)); %let n_plots = %eval(%klength(%kleft(%ktrim(%sysfunc(kcompress(&plotnames))))) - %sysfunc(klength(%sysfunc(kcompress(&plotnames,'| ')))) +1); %do i = 1 %to &n_plots; %local plot&i; %let plot&i = %kscan(&plotnames,&i,'|'); %end; /******************************************************************************************** * Define RTF Template: * -Call the rmrtftemplate macro to set up the formatting for the RTF output. * The font size and the margins are set by input parameters. All other formatting is set * directly within the macro. *********************************************************************************************/ %rmrtftemplate(fntsize = &rmfntsize_table, lrmargins = &&rmlrmargins_&orient, tbmargins = &&rmtbmargins_&orient); /******************************************************************************************** * Identify name of program and name of RTF file: * -Call rmsyspgmname macro to identify the program name. * -If a File ID is not specified by the user, the rmsyspgmname macro sets the File ID equal to * the program name. * -The program name and RTF file ID are output as global macro variables, RM_PGMNAME and RM_FILEID. *********************************************************************************************/ %rmsyspgmname(fileid=&fileid); /******************************************************************************************** * Identify Title and Footnotes: * -If the title is defined in the macro call, then it (and all of the footnotes) will be * defined by the macro parameters. * -If the title is not defined in the macro call, the %rmdpstitle macro is called. This * macro will go to the titles spreadsheet in order to find the title and footnotes. * -The title and footnotes are output to global macro vars, *********************************************************************************************/ %if %superq(title) ne %then %do; %global rm_title rm_foot1 rm_foot2 rm_foot3 rm_foot4 rm_foot5 rm_foot6 rm_foot7 rm_foot8 rm_foot9 rm_foot10 rm_foot11 rm_foot12 rm_foot13 rm_foot14 rm_foot15 rm_foot16 rm_foot17 rm_foot18 rm_foot19 rm_foot20; %let rm_title = &title; %let rm_foot1 = &foot1; %let rm_foot2 = &foot2; %let rm_foot3 = &foot3; %let rm_foot4 = &foot4; %let rm_foot5 = &foot5; %let rm_foot6 = &foot6; %let rm_foot7 = &foot7; %let rm_foot8 = &foot8; %let rm_foot9 = &foot9; %let rm_foot10 = &foot10; %let rm_foot11 = &foot11; %let rm_foot12 = &foot12; %let rm_foot13 = &foot13; %let rm_foot14 = &foot14; %let rm_foot15 = &foot15; %let rm_foot16 = &foot16; %let rm_foot17 = &foot17; %let rm_foot18 = &foot18; %let rm_foot19 = &foot19; %let rm_foot20 = &foot20; %end; %else %do; %rmdpstitle(fileid=&rm_fileid); %end; /******************************************************************************************** * Long footnotes with sysmbols occasionally wrap mid-word. Modify footnotes so they wrap on * a word boundary by replacing spaces with breaking spaces (unicode 0020). * -Replace all occurrances of 'unicode ' (regardless of case) with 'UNICODE'. Note that this * step removes the space after "unicode". This is done so unicode functions are not nested * when the 'unicode 0020' is inserted. * -Replace all blank spaces with "&rmescchar.{UNICODE0020}" (i.e. a breaking space). * -Replace all occurrances of 'UNICODE' (w/o a space) with 'UNICODE ' (with a space). *********************************************************************************************/ data _null_; %do j = 1 %to 20; %if %superq(rm_foot&j) ne %then %do; length fn&j $ 32000; fn&j = prxchange('s/unicode /UNICODE/i', -1, "&&rm_foot&j"); fn&j = tranwrd(kstrip(fn&j), ' ', "&rmescchar.{UNICODE0020}"); fn&j = tranwrd(fn&j, 'UNICODE', 'UNICODE '); call symput("rm_foot&j", fn&j); %end; %end; run; /******************************************************************************************** * Set Page Options and open the RTF destination. * -Captions style is defined as "s15". * -Template is set to the BnPTemplate. * -The ODS escape character is set to "&rmescchar.". * -All SAS titles are cleared as they would appear in the header of the document by default. *********************************************************************************************/ option nobyline nodate nonumber orientation="&orient"; ods listing close; ods rtf file = "&opath.&rmsep.&rm_fileid..rtf" wordstyle = '{\s15 caption;}' style = bnptemplate.rtf startpage=NO; ods escapechar="&rmescchar"; title; /******************************************************************************************** * Output Table: * -Create a dummy work dataset with one record per plot that will be output. * -Run Proc report, with compute block outputting a record for each plot passed into the macro * via the plotnames parameter. * -Call the rmouttitle macro to add titles and footnotes to the table. *********************************************************************************************/ data _rmtext; format text $12.; text = "&rmescchar.R'\par\ '"; %do i = 1 %to &n_plots; output; %end; run; %local tblwidth; %if %kupcase(&orient) = PORTRAIT %then %let tblwidth = 6; %else %if %kupcase(&orient) = LANDSCAPE %then %let tblwidth = 9; proc report data = _rmtext nowd; column text; define text / display style(column)=[cellwidth=&tblwidth.in] ' '; compute text; line_count + 1; %do i = 1 %to &n_plots; if line_count = &i then do; call define(_row_,'STYLE', %str(%')STYLE=[just=center postimage="&plotpath.&rmsep.&&plot&i...png"]%str(%')); end; %end; endcomp; %rmouttitle(outtype = graph); run; proc datasets nolist; delete _rmtext; quit; ods rtf close; ods listing; /******************************************************************************************** * Delete global reporting macro variables: * -Any global reporting macro variables created within this macro, or any macros called within * this macro, are deleted so as to not carry over to the next table/listing/figure. * -Any global reporting macro created prior to this macro, such as those created in %RMGSETUP, * are not deleted here since users may wish to call %RMGSETUP once for multiple graphs. *********************************************************************************************/ %symdel rm_pgmname rm_fileid rm_title rm_foot1 rm_foot2 rm_foot3 rm_foot4 rm_foot5 rm_foot6 rm_foot7 rm_foot8 rm_foot9 rm_foot10 rm_foot11 rm_foot12 rm_foot13 rm_foot14 rm_foot15 rm_foot16 rm_foot17 rm_foot18 rm_foot19 rm_foot20; %mend gengraph;