BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
js5
Pyrite | Level 9 js5
Pyrite | Level 9

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
That's where I'd probably use a format to ensure that Day 3 comes first or use SUBSTR to extract the number out of the group variable and make a helper variable from the day number, which would then sort correctly and you would not have to worry about it.
Cynthia

View solution in original post

6 REPLIES 6
ballardw
Super User

Add another variable that will break as needed. Set it as a NOPRINT variable in define statement so it doesn't appear.

Cynthia_sas
SAS Super FREQ

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

js5
Pyrite | Level 9 js5
Pyrite | Level 9

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:

  • raw values:
    • page 1: timepoint 1, timepoint 2
    • page 2: timepoint 3, timepoint 4
  • fold increase:
    • page 1: timepoint 2, timepoint 3
    • page 2: timepoint 4, timepoint 5

I was hoping I could avoid all this by breaking on a computed variable, but this appears not to be possible.

Cynthia_sas
SAS Super FREQ

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

js5
Pyrite | Level 9 js5
Pyrite | Level 9

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.

Cynthia_sas
SAS Super FREQ
That's where I'd probably use a format to ensure that Day 3 comes first or use SUBSTR to extract the number out of the group variable and make a helper variable from the day number, which would then sort correctly and you would not have to worry about it.
Cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1097 views
  • 0 likes
  • 3 in conversation