STEP 1. CREATE A PAGE VARIABLE IN THE FINAL DATASET BEFORE USING THE PROC REPORT PROCEDURE
A numeric variable containing
page number values will be used in the PROC REPORT procedure to generate Page X
of Y. To get page number values, first you have to figure out what is the
maximum number of rows each page body (excluding title, footnote, and free
margin space areas) can contain. The best way to get this number is to use the PROC
PEPORT procedure to test it. In theory, if there are no wrapped columns, no
blank rows, and assuming that each observation occupies only one row in the
output, the total number of pages should be equal to the number of total rows
divided by the maximum row number of a page if there is no remainder, or to
that value +1 if there is a remainder. However, almost every RTF output
contains blank rows at least for cosmetic purposes. Some RTF outputs such as
most of listings have wrapped columns, which means that one single observation
in the SAS dataset could be displayed in multiple rows depending on the maximum
length of the variable in that observation.
As a result, how many rows each page contains will vary. This makes the job to
create page numbers much more complicated.
The following three steps have been developed to get the
page number:
1). Get the
number of wraps for each wrapped column with the CEIL and LENGTH functions.
wrapx = CEIL(LENGTH(colx) /Nx) ;
wrapx stands for the number of wraps for column x.
Colx stands for
column x.
Nx stands for the maximum number of characters column x can
have. For example, if column x is 35
characters long, then replace Nx with 35.
2). Find out
the maximum wrap count with the MAX function:
maxwrap = MAX(wrap1, wrap2, , …) ;
3).
Calculate the page number.
DATA fin;
SET xyz ;
BY sitesubj ;
RETAIN pg 0 pgcnt 0 ;
IF FIRST.sitesubj THEN pgcnt = pgcnt + maxwrap + 1 ;
ELSE pgcnt = pgcnt + maxwrap ;
IF pgcnt > pnum THEN DO;
Pgcnt = maxwrap + 1;
Pg = pg + 1;
END;
RUN;
pg is the page number variable.
pnum stands for the maximum number of rows that each page body
can contain. For example, if the
maximum row number that each page body can contain is 30,
then replace pnum with 30.
STEP 2. CREATE A MACRO VARIABLE THAT CARRIES A VALUE FOR THE TOTAL NUMBER OF PAGES
The PROC SQL procedure can be used to create a macro
variable - &tpg that carries the maximum number of pages:
PROC SQL NOPRINT;
SELECT max(pg) into :tpg
FROM fin ;
QUIT;
STEP 3. GENERATE PAGE NUMBERS IN X of Y FORMAT IN ODS RTF OUTPUTS
The following macro generates RTF output.
ODS RTF FILE =
“xyz.rtf” ;
%MACRO Rept ;
%DO i
= 1 %to &tpg ;
TITLE1 J=L "xyz Inc." J=C
"Confidential" J=R "Page &i of &tpg" ;
PROC REPORT DATA = fin
(where=(pg= &i)) missing nowd headline headskip;
COLUMN pg col01 col02 col03
col04 ;
DEFINE pg / order order=internal
noprint ;
DEFINE col01 / … ;
……
BREAK after pg / page ;
RUN ;
%END ;
%MEND;
%Rept ;
ODS RTF CLOSE ;
CONCLUSION
SAS’s position on RTF is that the format is intended for
modification. However, this is not the case for drug submission. Once the final
batch run is finished, the outputs are not supposed to be modified any more.
The approach to generate page numbers in X of Y format as discussed above is
straightforward without having to deal with the Microsoft Word field code information.
A drawback is that the number of rows in each page may not be even. Some pages
may contain more rows with less white space whereas other pages may have more
white space.
However, the benefi
No comments:
Post a Comment