Hi, long time viewer and first time poster!
I'm making an RTF output using proc report and I want to define a column that increments with each new page of the RTF. I'm trying to use the _PAGE_ target in a compute statement to try to recognize when the RTF starts a new page but it seems to have a different definition of "page" than I do. I've read documentation, Googled, and even asked ChatGPT - does anyone here have any insight?
Here is the code I'm running:
data example;
do group = 1 to 3;
do i = 1 to 20;
var1 = group;
var2 = i;
output;
end;
end;
run;
ODS LISTING CLOSE;
ODS RTF FILE = "newpage.rtf";
PROC REPORT DATA = example;
COLUMN var1 var2 PAGE_COUNT;
DEFINE var1 / DISPLAY;
DEFINE var2 / DISPLAY;
DEFINE PAGE_COUNT / COMPUTED;
COMPUTE PAGE_COUNT;
PAGE_COUNT = 1;
endcomp;
COMPUTE AFTER _PAGE_;
PAGE_COUNT + 1;
LINE 'This should be at the end of every page';
endcomp;
RUN;
ODS RTF CLOSE;
ODS LISTING;
This is the (undesirable) RTF output it gives:
This is what I'm hoping I can end up with:
Thanks, Jacob
I would suggest that one solution would be to add a variable to your data to control appearance unless this "report" is going to frequently change fonts, cell border padding and such that change "page" size.
And do you actually want the "page_count" to appear in the body or was that just for demonstration?
Maybe something like this?
data example; do group = 1 to 3; do i = 1 to 20; counter=sum(counter,1); page_num=int(counter/25); var1 = group; var2 = i; output; end; end; run; ODS RTF FILE = "x:\newpage.rtf"; PROC REPORT DATA = example; COLUMN page_num var1 var2 ; define page_num /noprint order ; DEFINE var1 / DISPLAY; DEFINE var2 / DISPLAY; break after page_num/page; COMPUTE AFTER page_num; LINE 'This should be at the end of every page'; endcomp; RUN; ODS RTF CLOSE;
I would suggest that one solution would be to add a variable to your data to control appearance unless this "report" is going to frequently change fonts, cell border padding and such that change "page" size.
And do you actually want the "page_count" to appear in the body or was that just for demonstration?
Maybe something like this?
data example; do group = 1 to 3; do i = 1 to 20; counter=sum(counter,1); page_num=int(counter/25); var1 = group; var2 = i; output; end; end; run; ODS RTF FILE = "x:\newpage.rtf"; PROC REPORT DATA = example; COLUMN page_num var1 var2 ; define page_num /noprint order ; DEFINE var1 / DISPLAY; DEFINE var2 / DISPLAY; break after page_num/page; COMPUTE AFTER page_num; LINE 'This should be at the end of every page'; endcomp; RUN; ODS RTF CLOSE;
Thanks for the quick reply! I've always known in the back of my mind something like this was an option, I've been trying to find a way to have proc report compute the variable automatically if at all possible though. I'm trying to do this for a few different reports that have different sizes of header and footer so the number of rows per page may not always be the same. Also, page_count is just for demonstration, it would not be displayed on the final table.
Not for RTF. RTF is like HTML in that sense. What "page" something appears on is depended on the tool used to render the text of the RTF file. Choose a different printer (or page size) and where the page breaks appear will change.
If you want fixed pages make a PDF file.
Ah okay, that's what I feared. Thank you for the confirmation though Tom, I really appreciate it! Sounds like the previous response is the best workaround then since I'm limited to RTFs. Thanks again, Jacob
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.