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

Hi SAS experts,

I wonder if there is a way how to insert row with group name after splitting group variable to two pages in RTF file.

For example I have report such as:

<----- page 1 ----->
VAR1      | VAR2 | ...
Country | | UK | | France | | Germany | | <----- page 2 ----->
VAR1 | VAR2 | ...
US | |
Russia | |

And I want the result to be like this:

<----- page 1 ----->
VAR1      | VAR2 | ...
Country   |      |
  UK      |      |  
  France  |      |
  Germany |      |

<----- page 2 ----->
VAR1      | VAR2 | ... 
Country (contd.)
 US       |      |
 Russia   |      |

Is there a way how I can check if the row is on new page so I can insert row with group name before it?

Thank you for any advice

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, there is no automatic way of doing this simply.  You will need to format your data in a way that the data describes where the splits will be.  What I tend to do is to assign in a datastep each of the records I want to appear on one page.  Then I use that variable to break my report.  With this you could add in changes to the data to get the output you want.  So assume that 10 records max per page:

data want;
  set in;
  retain pge 1;
  if mod(_n_,10)=0 then pge=pge+1;
run; 

You can then break on pge variable.  Now you need to alter the data after the page change, maybe something like:

data want;
  set in;
  retain pge chg;
if _n_=1 then pge=1; if mod(_n_,10)=0 then do;
pge=pge+1;
chg=1;
end;
if chg=1 and lag(region)=catx(" ",region,"(contd.)) then region=catx(" ",region,"(contd.)");
else chg=0; run;

Not tested this, but what I am effectively trying to do is to change the data looks like:

Germany              pge=1

Germany              pge=1

Germany (contd.) pge=2

 

In this way you control when the page break happens and as the data looks like the output the group should automatically handle that.

 

 

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You would use a compute block, but you might need a flag in your data.  I.e.

proc report ...;
  columns _all_;
  define pge / noprint;
  ...;

  break after pge / page;

  compute before page;
    length txt $20;
    if pge=1 then txt="Country";
    else txt="Country cont.";
    line txt;
  endcomp;
run;
Matyas
Fluorite | Level 6

Thanks,

I used that as example but the problem is more complicated. I have more than one group and I am seeking for general solution, that will input line on next page with the name of splitted group variable. Is that possible?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You need to provide examples of what you have, what you want, and explain between them, I cannot guess.

Matyas
Fluorite | Level 6

Yeah, sorry I was not accurate.

What I have is this:

have.JPG

What I want is this:
want.JPG

The code to produce output is:

data in;
infile datalines delimiter=','; 
input region $ country $ status $ Total $ GroupA $ GroupB $ ord;
datalines;
Asia ,Taiwan ,Asia ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Asia ,Taiwan ,Taiwan ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Asia ,Taiwan ,town1 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Asia ,Taiwan ,town2 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Asia ,Taiwan ,town3 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Asia ,Taiwan ,town4 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Asia ,Taiwan ,town5 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Asia ,Taiwan ,town6 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,1
Europe ,Belgium ,Europe ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,Belgium ,Belgium ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,Belgium ,town1 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,Belgium ,town2 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,Belgium ,town3 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,Belgium ,town4 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,Belgium ,town5 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,Belgium ,town6 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,2
Europe ,France ,France ,xx (xx%) ,xx (xx%) ,xx (xx%) ,3
Europe ,France ,town1 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,3
Europe ,France ,town2 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,3
Europe ,France ,town3 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,3
Europe ,France ,town4 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,3
Europe ,Germany ,Germany ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town1 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town2 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town3 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town4 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town5 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town6 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town7 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Germany ,town8 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,4
Europe ,Greece ,Greece ,xx (xx%) ,xx (xx%) ,xx (xx%) ,5
Europe ,Greece ,town1 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,5
Europe ,Greece ,town2 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,5
Europe ,Greece ,town3 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,5
Europe ,Greece ,town4 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,5
Europe ,Greece ,town5 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,5
Europe ,Greece ,town6 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,5
Europe ,Israel ,Israel ,xx (xx%) ,xx (xx%) ,xx (xx%) ,6
Europe ,Israel ,town1 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,6
Europe ,Israel ,town2 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,6
Europe ,Israel ,town3 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,6
Europe ,Israel ,town4 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,6
Europe ,Israel ,town5 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,6
Europe ,Israel ,town6 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,6
Europe ,Italy ,Italy ,xx (xx%) ,xx (xx%) ,xx (xx%) ,7
Europe ,Italy ,town1 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,7
Europe ,Italy ,town2 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,7
Europe ,Italy ,town3 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,7
Europe ,Italy ,town4 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,7
Europe ,Italy ,town5 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,7
Europe ,Italy ,town6 ,xx (xx%) ,xx (xx%) ,xx (xx%) ,7
;run;

OPTIONS ORIENTATION=landscape nodate nonumber nocenter papersize=A4 helpbrowser=sas;
ODS escapechar='#';
ODS RTF bodytitle nogtitle startpage=yes
file="C:\table.rtf";

ods listing close;
proc report data=in nowd split="~" out=pom;
	columns region country ord status Total GroupA GroupB;

	define region/noprint;
	define country/noprint;
	define ord/order noprint;

	define status/display style(column)=[indent=35 cellwidth=9.16cm] "Region -~  Country~    Site";
	define total/display style(column)=[indent=0 cellwidth=4.47cm] "Region";
	define GroupA/display style(column)=[indent=0 cellwidth=4.47cm] "GroupA";
	define GroupB/display style(column)=[indent=0 cellwidth=4.47cm] "GroupB";	

	/*indentation region - country - town*/
	compute status;
	 if status = region then do;
	  	 status = catx(" ", status, "-");
         call define(_col_, "style", "style=[indent=0]");
     end;
	 if status = country then do;
         call define(_col_, "style", "style=[indent=20]");
     end;
    endcomp;
	
    compute before ord;
		line ' ';
    endcomp;

run;
ods rtf close;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, there is no automatic way of doing this simply.  You will need to format your data in a way that the data describes where the splits will be.  What I tend to do is to assign in a datastep each of the records I want to appear on one page.  Then I use that variable to break my report.  With this you could add in changes to the data to get the output you want.  So assume that 10 records max per page:

data want;
  set in;
  retain pge 1;
  if mod(_n_,10)=0 then pge=pge+1;
run; 

You can then break on pge variable.  Now you need to alter the data after the page change, maybe something like:

data want;
  set in;
  retain pge chg;
if _n_=1 then pge=1; if mod(_n_,10)=0 then do;
pge=pge+1;
chg=1;
end;
if chg=1 and lag(region)=catx(" ",region,"(contd.)) then region=catx(" ",region,"(contd.)");
else chg=0; run;

Not tested this, but what I am effectively trying to do is to change the data looks like:

Germany              pge=1

Germany              pge=1

Germany (contd.) pge=2

 

In this way you control when the page break happens and as the data looks like the output the group should automatically handle that.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1981 views
  • 0 likes
  • 2 in conversation