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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 499 views
  • 0 likes
  • 2 in conversation