The SAS Output Delivery System and reporting techniques

Proc report

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Proc report

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 ?


Accepted Solutions
Solution
‎11-21-2017 03:13 PM
Occasional Contributor
Posts: 15

Re: Proc report

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 Smiley Happy 

View solution in original post


All Replies
Super User
Super User
Posts: 9,193

Re: Proc report

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;
Occasional Contributor
Posts: 15

Re: Proc report

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. 

Super User
Super User
Posts: 9,193

Re: Proc report

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).

Solution
‎11-21-2017 03:13 PM
Occasional Contributor
Posts: 15

Re: Proc report

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 Smiley Happy 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 224 views
  • 0 likes
  • 2 in conversation