BookmarkSubscribeRSS Feed
Sche
Calcite | Level 5

My data contains the following variables TRT SUBJECTID TESTNAME VISIT DATE RESULT. 

I am displaying this data as a listing in RTF file format. The data contains many subjects in three different treatment groups(TRT). 

The TRT value appears as a subtitle in the RTF output (achieved using BY TRT  in PROC REPORT). Each subject has multiple TESTNAMEs and multiple VISITs. So the data for each subject spans several pages vertically (the columns on the RTF listing being SUBJECTID TESTNAME VISIT DATE and RESULT all fitting on a single page horizontally but flowing over several pages for each SUBJECTID vertically). The SUBJECTID prints on the first row of the subjects data (as a grouping variable). I need the SUBJECTID to display on the first row of each new page when a subjects data flows over to the next page vertically. 

 

    My PROC REPORT code is as follows:

PROC REPORT DATA=  xdata;

      by TRT; COLUMN PG SUBJECTID TESTNAME VISIT DATE RESULT: 

DEFINE PG /order order=internal noprint;

DEFINE SUBJECTID / order order=internal style(header)={cellwidth=0.9in just=l};

.

. ;

COMPUTE BEFORE SUBJECTID;

   line " ";

ENDCOMP;

BREAK AFTER PG/PAGE;

run;

The PG value is derived as PG=ceil(_n_/14); in order to get a limited number of rows per page. I notice that the SUBJECTID prints on subsequent pages when there is a change of PG value. But if a subject has the same PG value throughout his/her data but the PROC REPORT paging moves to the next page,  that SUBJECTID does not print on that next page because the PG value is the same. So it appears the BREAK AFTER PG/PAGE (and change in PG value) is impacting the printing of SUBJECTID on next page. I cannot solve the issue by using BREAK AFTER SUBJECTID/PAGE because that would only print the SUBJECTID value at the beginning of each new subject's data. 

I tried leaving out the PG variable totally so that PROC REPORT determines the number of rows on each page. But this does not solve the issue. Also using GROUP BY instead of ORDER ORDER=internal on DEFINE SUBJECTID row of PROC REPORT does not make a difference. 

 

To describe my example visually the output looks similar to below example: 

 

Listing of LAB Results 

Page 1 of 3

Treatment A

_____________________________________________________________________________________________________________

SUBJECTID         TESTNAME                        VISIT                                           DATE               RESULT 

______________________________________________________________________________________________________________

400-2010A         Hemoglobin                 Day 10                                           20Sep2023             XX

                                Calcium                        Day 12                                            22Sep2023             XX 

                              Magnesium                   Day 20                                           02Oct2023              XX

 

 

Listing of LAB Results 

Page 2 of 3 

Treatment A 

_______________________________________________________________________________________________________

SUBJECTID                 TESTNAME              VISIT                             DATE                            RESULT 

__________________________________________________________________________________________________________                                 

 missing                       ALT                            Day 21                           03OCT2023                     XX

                                       AST                            Day 22                           04Oct2023                     XX 

                       

I am needing SUBJECTID value to show on the new page (page 2 in above example) where I have inserted 'missing' in red text. 

Any suggestions on how to resolve this? 

2 REPLIES 2
Ksharp
Super User

Interesting. You need to use TAGSETS.RTF destination rather than RTF destination .

P.S. also need help of SPANROWS option.

 

data have;
set sashelp.heart(obs=1000);
keep bp_status  weight_status smoking_status weight height;
run;
proc sort data=have; by bp_status;run;

options orientation=landscape;
ods tagsets.rtf file='c:\temp\temp.rtf' style=journal;
proc report data=have nowd spanrows;
by bp_status;
column  weight_status smoking_status weight height;
define weight_status /order ;
define smoking_status /order ;
define weight/display ;
define height/display;
run;
ods tagsets.rtf close;

Ksharp_0-1711334132496.png

 

 

 

Patrick
Opal | Level 21

Just by searching through the SAS Communities here it appears there is no simple option only way to do this with Proc Report. What appears to be possible is to pre-process your data and add a "break" variable which you then use in Proc Report as your first group variable without printing it.

%let lines_per_page=30;
data a;
  do i=1 to 100;
    grp="grp";
    grp2=floor(i/12);
    break=floor(i/&lines_per_page);
    output;
  end;
run;

ods rtf file="%sysfunc(pathname(work))\test.rtf";
proc report data=a ps=&lines_per_page spanrows;
  column break grp grp2 i;
  define break /group noprint;
  define grp/group order=internal;
  define grp2/group order=internal;
  define i/display;
run;
ods rtf close;

Patrick_0-1711334211806.png

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 299 views
  • 2 likes
  • 3 in conversation