Hello,
I am trying to control the flow of my document by having more control over where page breaks are inserted. I am using proc report and outputting it to ods word.
I am aware of
break after groupvar / page
This would make a new page after each new groupvar value. Is there a way of having a new page after every second groupvar value without preprocessing the data? I know it can be acheived with preprocessing, e.g. https://support.sas.com/resources/papers/proceedings12/389-2012.pdf
Unfortunately, as I am using a NOTSORTED format for display, getting the data in the right order for preprocessing and inserting a manual page break variable is somewhat tricky. Thanks!
Add another variable that will break as needed. Set it as a NOPRINT variable in define statement so it doesn't appear.
Hi:
Unfortunately, as @ballardw explained, you cannot do a page break automatically for every second group variable. You really do need to set your own manual "helper" variable to control the breaking. Not sure why you need NOTSORTED. There are other ways to control the ORDER. In the program below, which uses some of SASHELP.CARS, a user-defined format creates 3 helper variables that I think does what you want.
** Create user-defined format for all helper variables;
** based on values of MAKE;
proc format;
value $biggrp 'Volvo', 'BMW', 'Acura', 'Ford' = '1'
'Audi', 'Chevrolet','GMC', 'Honda' = '2';
value $brkgrp 'Volvo', 'BMW'='1a'
'Acura', 'Ford' = '1b'
'GMC', 'Audi'='2a'
'Honda','Chevrolet' = '2b';
value $sortord 'Volvo'='01'
'BMW'='02'
'Acura'='03'
'Ford' = '04'
'GMC'='11'
'Audi'='12'
'Honda'='13'
'Chevrolet' = '14';
run;
** create new helper variables BIGGRP, BRKGRP and SORTORD using PUT function;
data mycars;
length biggrp $1 brkgrp $2 sortord $2;
set sashelp.cars;
where make in ('Volvo','BMW', 'Acura', 'Ford', 'Chevrolet', 'Audi', 'GMC', 'Honda');
biggrp = put(make,$biggrp.);
brkgrp = put(make,$brkgrp.);
sortord = put(make,$sortord.);
run;
** make BIGGRP, BRKGRP and SORTORD helper variables NOPRINT when ;
** report is organized as desired with desired breaks and summary lines;
proc report data=mycars
style(summary)=Header;
column biggrp brkgrp sortord make model msrp mpg_city;
define biggrp / order;
define brkgrp / order ;
define sortord / order;
define make / display;
define model / display;
define msrp / mean 'Avg MSRP';
define mpg_city / mean 'Avg MPG City' f=7.2;
break after brkgrp / page summarize;
compute after brkgrp;
model = 'Average for this subgroup';
endcomp;
run;
Cynthia
Thank you for the suggestions. I think for my particular application I would need to sort by formatted values first with proc sort, followed by a data step using by processing and bumping the helper var every 2nd group variable. The reason being that the group variables I need two of per page are timepoints, and I need this both for raw values and for fold increase. Fold increase does not make sense for the first, baseline timepoint, which shifts the categories on each page by one:
I was hoping I could avoid all this by breaking on a computed variable, but this appears not to be possible.
Hi:
A computed variable can only have one usage -- to be able to break on a specific variable, it must be a GROUP or ORDER variable. So a calculated variable in PROC REPORT can't be both COMPUTED and GROUP/ORDER. That's the reason for making helper variables outside of PROC REPORT -- so they can have the usage of GROUP or ORDER, but your logic seems straightforward to implement with helper variables. I agree, that sorting first makes sense, but I did my funky ordering of the MAKE variable only because you specifically mentioned using NOTSORTED and I thought that meant you had some special order that needed to be maintained on the report.
Cynthia
Funky order comes on top of what I wrote - my group variables are Day 3, Day 12, Day 25. Sorting alphapetically puts Day 3 at the end.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.