/* * pageof macros. * * start_pageof(placeholder=@@) * placeholder= a unique string that will not appear in your data, * much like the ods escapechar. The default is @@, * selected because I don't expect it to appear in much * output and it's about the same width as a 2-digit * page number. If you have a very long document, a * a longer string would be good; for a one-digit * page number, something like .. or ,, might be * better. * * end_pageof(tempfile, filename); * tempfile Is the name of the temporary file supplied to * ODS PRINTER. * filename Is the name of the final postscript file. * * Usage: * %start_pageof; * ods ps file="pageof.tmp" style=pageof; * : * [sas code] * : * ods ps close; * %end_pageof("pageof.tmp", "myfile.ps"); */ %let saved_placeholder = ; %macro start_pageof(placeholder=@@); %let saved_placeholder = &placeholder; proc template; define style styles.pageof; parent = styles.printer; Style PageNo from TitlesAndFooters / font = fonts("strongFont") cellpadding = 0 cellspacing = 0 pretext = "Page " posttext = " of &placeholder" ; end; run; %mend; %macro end_pageof(tempfile, permfile); data _null_; infile &tempfile truncover; length line $25000; input line $char.; place = index(line, "%%Pages: "); if place = 1 then do; if index(line, "(atend)") = 0 then do; pages = substr(line, 10); call symput("pagecnt", trim(pages)); end; end; run; %put page count = &pagecnt; data _null_; infile &tempfile lrecl=25000 pad; file &permfile lrecl=25000; length line $25000; input line $char.; place = index(line, "&saved_placeholder"); if place > 0 then do; line = substr(line, 1, place-1) || "&pagecnt" || substr(line, place+length("&saved_placeholder")); end; put line; run; %mend;