BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8


I'm preparing datastep to create proc report. So in datastep I have the variables treament and pg. I want to
display data per treatment group in separate pages. But while creating pg, same value is present for both treatments.
So in proc report a page name is repeated two times. I want to increment pg of treatment b,when a and b have same pg.
from below:

pg is derived as
pg=ceil(_n_/8); /**here I'm opting 8, it can change to any value**/

treatment   pg
Z               1
Z               2
L               2
L               3

to

treatment pg
Z              1
Z              2
L              3
L              4

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hi @SASPhile,

 

I take it that you derive your current dataset (let's call it HAVE) from another dataset (HAVE0) and compute the page number as shown.

 

Example:

data have0(drop=i);
do treatment='Z', 'L';
  do i=1 to 10;
    output;
  end;
end;
run;

data have;
set have0;
pg=ceil(_n_/8);
run;

To obtain the improved page numbers you could start with HAVE0 and derive variable PG as follows:

data want(drop=_ctr);
set have0;
by treatment notsorted;
if first.treatment then _ctr=1;
else _ctr+1;
if mod(_ctr,8)=1 then pg+1;
run;