BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jeanderson
Fluorite | Level 6

Part of a macro I wrote creates a report for 1 to many patients, depending on the data. The data is first transposed, and the list of patients is put into a macro variable to be used as variables in the Proc Report. It's been requested that each patient (in record_id_list) is on their own page in the report. Is there a way to add a page break dynamically?

 

/* &i is a site - this report is created for each site that has data */

proc transpose data = new_saes&i out=new_saes_trans&i
label=des name=redcap_var prefix=pat;
id record_id;
idlabel sae_1;
var sae3 sae4 sae5 sae5a sae6 sae7 sae8 
sae9 sae10 sae11 sae12 sae13 sae14 sae15 sae15a sae16;
run;



/* Get variable names for each patient to use in proc report */
%let record_id_list =; proc sql noprint; select name into :record_id_list separated by ' ' from dictionary.columns where libname='WORK' and upcase(memname)="NEW_SAES_TRANS&i" and upcase(name) like 'PAT%'; quit; /* Create reports. */ proc report data=new_saes_trans&i style(column)=[fontsize = 9pt]; column des &record_id_list; define des / " " id style={fontsize = 9pt width=480 just=left}; run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:
I am having a hard time visualizing the structure of your DATA and also don't understand how &i is being set and what is in the &record_id_list macro variable and how it is being used in conjunction with the DES variable. Without any data to run or to visualize, it's nearly impossible to answer your question about whether it is possible to put your description column on every page with only one other column per page.

The short answer is yes, it is possible, but to me, that sounds like multiple PROC REPORT steps -- not within one PROC REPORT step.

Something like this:

data test;
  set sashelp.class;
  des=catx(' ','The Age is:',age);
run;
 
%let record_id_list = name~sex~height~weight;
%let stop=%sysfunc(countw(&record_id_list,~));
%put &=record_id_list;
%put &=stop;
 
%macro doonecol;
 
%do i = 1 %to &stop;
%let thiscol = %scan(&record_id_list,&i,~);

proc report data=test;
  column des &thiscol;
  define des / order ' ';
  title "&i] Want to see DES and &thiscol variable";
  title2 "every value of DES starts a new page";
  break after des / page;
run;
%end;

%mend doonecol;

 %doonecol


In this program, DES was created for every age. And the variables I want to see separately are name, sex, height and weight. I just manually made &record_id_list, since I couldn't envision what your macro variable looked like. In my PROC REPORT code, the DES variable starts on a new page for every unique value of DES and then shows only the one column taken out of &record_id_list using %SCAN.  I am sure my example is not what you're describing, but as I said, I can't visualize what your data is like and I've done two examples, so perhaps someone else understands what you need to do based on your description and will chime in with more suggestions.

 

Cynthia

View solution in original post

6 REPLIES 6
ballardw
Super User

Which variable has the desired name in the data set new_saes&I? Or variables if there are multiple  name fields.

If a single one then the transpose would likely be either not needed or modified.

 

Sort that data set by the name variable(s).

 

Use BY the name variable in proc report. By default that would be a Name=XXXXXXXX for each one before the table for that person.

You likely ODS destinations (other than HTML which doesn't really have the concept of "page" in the manner you are using it) have options to have each by group on a separate page. RTF for example uses STARTPAGE=BYGROUP, ODS Excel or Tagsets.excelxp use options=(sheet_interval='bygroup')

Cynthia_sas
SAS Super FREQ

Hi:

  I'm not sure I understand your TRANSPOSE or your PROC REPORT step or what you mean by dynamically doing a page break. PROC REPORT will perform a page break easily, as illustrated in the example below. I am using AGE as the variable that causes the page break. Every group of rows that are the same age will appear on a separate page. There are 2 ways to make this happen: 1) use PAGE processing with PROC REPORT or 2) use BY group processing. Each method in the example below produces 3 pages -- one page for each age in the subset of data.

 

Cynthia

 

**Here's some code to test;

proc sort data=sashelp.class out=class;
  by age;
  where age in (12, 13, 14);
run;

ods rtf file='c:\temp\method1.rtf';
proc report data=class;
  title '1) Use PAGE option in PROC REPORT';
  column age name sex height weight;
  define age / order noprint;
  define name / order;
  break before age / page;
  compute before _page_ / style=Header{just=c};
    line 'Age is: ' age 2.0;
  endcomp;
run;
ods rtf close;

ods rtf file='c:\temp\method2.rtf';
options nobyline;
proc report data=class;
  title '2) Use BY Group Processing for Age: #byval1';
  by age;
  column name sex height weight;
  define name / order;
run;
ods rtf close;
jeanderson
Fluorite | Level 6

Because of the PROC TRANSPOSE, the variables I want to break by are actually the columns. Is it possible to put my description column on every page with only one other column per page?

Cynthia_sas
SAS Super FREQ

Hi:
I am having a hard time visualizing the structure of your DATA and also don't understand how &i is being set and what is in the &record_id_list macro variable and how it is being used in conjunction with the DES variable. Without any data to run or to visualize, it's nearly impossible to answer your question about whether it is possible to put your description column on every page with only one other column per page.

The short answer is yes, it is possible, but to me, that sounds like multiple PROC REPORT steps -- not within one PROC REPORT step.

Something like this:

data test;
  set sashelp.class;
  des=catx(' ','The Age is:',age);
run;
 
%let record_id_list = name~sex~height~weight;
%let stop=%sysfunc(countw(&record_id_list,~));
%put &=record_id_list;
%put &=stop;
 
%macro doonecol;
 
%do i = 1 %to &stop;
%let thiscol = %scan(&record_id_list,&i,~);

proc report data=test;
  column des &thiscol;
  define des / order ' ';
  title "&i] Want to see DES and &thiscol variable";
  title2 "every value of DES starts a new page";
  break after des / page;
run;
%end;

%mend doonecol;

 %doonecol


In this program, DES was created for every age. And the variables I want to see separately are name, sex, height and weight. I just manually made &record_id_list, since I couldn't envision what your macro variable looked like. In my PROC REPORT code, the DES variable starts on a new page for every unique value of DES and then shows only the one column taken out of &record_id_list using %SCAN.  I am sure my example is not what you're describing, but as I said, I can't visualize what your data is like and I've done two examples, so perhaps someone else understands what you need to do based on your description and will chime in with more suggestions.

 

Cynthia

jeanderson
Fluorite | Level 6

From everything I've been able to find in my internet searches, it seems like I would have to set up a macro to loop through my &record_id_list and generate a report for every column variable listed.

 

I am unable to give out the data because of the nature of my work, and it's hard to provide more code as this is just a part of a much larger program.

 

Thank you for your responses!

Cynthia_sas
SAS Super FREQ
Hi:
Well, it's good to know I wasn't too far off the track. My macro program has a %DO loop to generate a PROC REPORT step for each column in my &record_id_list macro variable.

Cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 2173 views
  • 1 like
  • 3 in conversation