Hello All, I want to get an RTF output which contains no more than 4 observations per page and which goes to a next page when having a new ID.
Any suggestion ?
It works after doing a simple change:
data want; set have; retain pge cnt; by id; if _n_=1 then do; pge=1; cnt=1; end; else if first.id then do; pge=pge+1; cnt=1; end; else do; if cnt=4 then do; pge=pge+1; cnt=1; end; else cnt=cnt+1; end; run;
thank you very much 🙂
Yes, several ways of doing it. First and most simple is to add a page into your data;
data want; set have; retain pge; if _n_=1 then pge=1; if mod(_n_,4)=0 then pge=pge+1; run; ods rtf file=...; proc report data=want ...; by page; ... run;
Not resolved:When I have a new ID, some of their observation will not be in the appropriate page.
Example:
obs ID AE
1 1 nausea
2 1 headache
. 1 diarrhea
. 1 etc..
20 1
21 2
. 2
. 2
35 2
36 3
37 3
38 3
39 4
. 4
. 4
In this example, we will have the first observation of ID number 3 with the last three observation of ID number 2 (all in page 9). But I want to have the last three observations of ID number 2 in page 9 and the three observations of ID 3 in page 10 and so on.
This is where specifying your problem fully really helps. Post test data - in the form of a datastep, and exactly what you want to see out. At a guess, you would need to change the logic in the datastep to what you want your output to look like, maybe something like:
data want; set have; retain pge cnt; by id; if _n_=1 then do; pge=1; cnt=1; end; else if first.id then do; pge=pge+1; cnt=cnt+1; end; else do; if cnt=4 then do; pge=pge+1; cnt=1; end; else cnt=cnt+1; end; run; ods rtf file=...; proc report data=want ...; by page; ... run;
This will count records within id and if > 4 then set new page, and if new id then set new page (its a bit overcomplicated, to show the workings).
It works after doing a simple change:
data want; set have; retain pge cnt; by id; if _n_=1 then do; pge=1; cnt=1; end; else if first.id then do; pge=pge+1; cnt=1; end; else do; if cnt=4 then do; pge=pge+1; cnt=1; end; else cnt=cnt+1; end; run;
thank you very much 🙂
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 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.
Ready to level-up your skills? Choose your own adventure.