BookmarkSubscribeRSS Feed
BigPete
Obsidian | Level 7

Right now I'm actually working on outputting PROC REPORT result into RTF using a prewritten SAS code but trying to add a little tweak. So it looks like the "compute before _page_" part does the trick inserting text before the table portion. Trying to figure what to add to break introductory texts and table into separate pages. I tried something like "break before _page_ / page;" but I'd get the error message "ERROR: The BREAK variable _page_ is not one of the GROUP or
ORDER variables." Any suggestions?

 

PROC REPORT DATA = x(keep=&varname &ds) MISSING STYLE(REPORT)=[width=100% BACKGROUND=WHITE BORDERCOLOR=WHITE BORDERWIDTH=0 ASIS=OFF FONTSIZE=2] NOWD contents="&varname: &varlabel";

COLUMN puforder_&varname &varname &varname=vallabel DUMROW N PCTN; COMPUTE &varname; COUNT+1; if (mod(count,2))=0 then call define(_row_, 'STYLE', 'STYLE=[BACKGROUND=WHITE]'); ENDCOMP; COMPUTE before _page_/STYLE=[JUST=L FONTSIZE=2]; line "^{STYLE[fontsize=22 fontweight=bold]&varname: &varlabel}"; /*LINE "";*/ line "^{STYLE[width=100%]^{newline}&varintro}"; LINE ""; endcomp; define puforder_&varname /group order=internal noprint; DEFINE &varname /"Value" GROUP ORDER=INTERNAL STYLE(COLUMN)=[WIDTH=10% JUST=C FONTSIZE=2] STYLE(HEADER)=[JUST=C FONTSIZE=2] ; DEFINE vallabel /"Label" GROUP ID STYLE(COLUMN)=[WIDTH=60% JUST=L FONTSIZE=2] STYLE(HEADER)=[JUST=L FONTSIZE=2] FORMAT=&formt.. NOPRINT ; DEFINE DUMROW /COMPUTED "Label" STYLE(COLUMN)=[WIDTH=60% JUST=L FONTSIZE=2] STYLE(HEADER)=[JUST=L FONTSIZE=2] width=65; DEFINE N /"Frequency" STYLE(COLUMN)=[WIDTH=15% JUST=R FONTSIZE=2] STYLE(HEADER)=[JUST=R FONTSIZE=2] FORMAT=COMMA12. ; DEFINE PCTN /"%" STYLE(COLUMN)=[WIDTH=10% JUST=R FONTSIZE=2] STYLE(HEADER)=[JUST=R FONTSIZE=2] FORMAT=PERCENT7.1 ; COMPUTE DUMROW /CHAR LENGTH = 65; IF _BREAK_="_RBREAK_" THEN DO DUMROW = 'Total'; END; ELSE DUMROW=PUT(vallabel, &formt..); IF DUMROW = 'Total' THEN CALL DEFINE (_ROW_, 'STYLE', "STYLE=[BACKGROUND=LIGHT GRAY FONTSTYLE=ITALIC FONTSIZE=2]"); ENDCOMP; RBREAK AFTER / SUMMARIZE; COMPUTE AFTER/STYLE=[JUST=L FONTSIZE=2]; LINE " "; LINE "Width: &varwidth; Decimal: 0"; LINE "Variable type: numeric"; ENDCOMP; RUN;
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
_PAGE_, like _BREAK_ is a unique internal type of reference. In this case, you can do a COMPUTE BEFORE _PAGE_ because PROC REPORT knows when a page is going to be generated, based on the usages of the items on the report. Sometimes, in programs like this, people often create a fake page breaking variable so they can control the breaks and what text gets written out. To see a concrete example of all the special places where PROC REPORT can write LINE output into a report look at this paper https://support.sas.com/resources/papers/proceedings17/SAS0431-2017.pdf starting on page 7 - page 9.
Cynthia
BigPete
Obsidian | Level 7

I already have COMPUTE BEFORE _PAGE_ in the code which looks like it helps display texts right before the table part of PROC REPORT. But any idea how I can go further to split them into having COMPUTE BEFORE _PAGE_ contents on page 1 and table part of PROC REPORT on page 2?

Cynthia_sas
SAS Super FREQ

Hi,
Not really without more information. What's in your macro variables &VARINFO? What are your other macro variables? What is the structure of the data? What is your custom format? It is very hard to make concrete suggestions without understanding what your data looks like and what all your macro variables are doing.

Bottom line, you can't insert a page break into the COMPUTE BEFORE _PAGE_ text that you're writing out and you can't perform break processing on the special location of _PAGE_ the is created by PROC REPORT. When I want to put some text on page 1 and then have the report start on page 2, how I do it really depends on what needs to be put on page 1. Most of the student questions I get have revolved around either generating a title page on page 1 or on having some kind of explanatory text paragraph on page 1. Typically, I illustrate those type of report requests using 2 PROC REPORT steps that will produce output like this:

Cynthia_sas_0-1651327755634.png

data varinfo;
  length infoline $60;
  infile datalines dlm=',' dsd;
  input ordvar infoline $;
datalines;
1,"Twas brillig and the slithy toves"
2,"Did gyre and gimble in the wabe"
3,"All mimsy were the borogroves"
4,"And the mome raths outgrabe"
5,"Lewis Carroll"
;
run;
title;
   
options nodate nonumber;
ods escapechar='^';
footnote j=r h=12pt 'Page ^{thispage}';
ods rtf file='c:\temp\page1_page2.rtf';
proc report data=varinfo noheader
     style(report)={rules=none frame=void cellspacing=0}
	 style(column)=Header{background=white color=black font_size=20pt};
  column ordvar infoline;
  define ordvar / order noprint;
  define infoline / display;
  compute infoline;
    if ordvar = 5 then do;
	   call define(_col_,'style','style={color=green just=r}');
	end;
  endcomp;
run;
 
title 'Main report starts on this page';
proc report data=sashelp.class;
compute before _page_/ style=Header;
   line 'Should start on Page 2';
endcomp;
run;
 
ods rtf close;

  But your report looks more like a pre-summarized report or some kind of data dictionary and it's hard to visualize what you are getting and how you want it to change without any context or sample data to run that shows all your code, your macro variables, your formats and your ODS statements.


  The only way to control the location dictated by using _PAGE_ is either allow PROC REPORT to control the logical pages based on the variable values for group or order variables used as PAGE variables or for you to make a fake page breaking variable. This puts the COMPUTE BEFORE _PAGE_ text on the same physical page as the beginning of the logical page. So if the logical page will start on page 1 then the COMPUTE BEFORE _PAGE_ text output will be also placed at the top of the table on page 1.

If I just needed a caption before or after a table, but outside the boundary of the table, my tendency would be to use ODS TEXT. In addition, changing the style of the ODS TEXT font will need to be done because the default style of the ODS TEXT font is left justified in the data font size. With COMPUTE _PAGE_, your text strings are restricted to the boundaries of the table. So for example, if your page in RTF has 1 inch margins on an 8.5 inch portrait document and your table is centered at 4 inches wide, your COMPUTE BEFORE _PAGE_ will be placed within that 4 inch wide table boundary. If you want the _PAGE_ text to span from margin to margin, which is 6.5 inches, you have to move to the TITLE statement or to ODS TEXT or to a separate PROC step. A separate PROC step will always start on a new page, unless you have changes to the STARTPAGE option in ODS RTF or ODS PDF, which is why I most always use the technique shown above for creating title pages or some related text before the main report. 

Cynthia

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1665 views
  • 0 likes
  • 2 in conversation