DATA Step, Macro, Functions and more

Proc Report-One subject data per page

Reply
Contributor
Posts: 24

Proc Report-One subject data per page

Dear All,

 

Can anyone please guide on how to handle only single subject data per page in proc report ?

 

Regards,

Rajesh

Super Contributor
Posts: 394

Re: Proc Report-One subject data per page

Use the PAGE option on a BREAK AFTER statement.

Contributor
Posts: 24

Re: Proc Report-One subject data per page

Hi Tom,

 

I have used that option and i am looking for alternate also where i can use some macro variables and populate the subject id in the header part/title of page.

Contributor
Posts: 24

Re: Proc Report-One subject data per page

Hi, 

 

I used below but not  working as per my requirement.

 

data a;
input x $ score ;
datalines;
a 1
a 2
a .
a 3
a 4
b .
b 4
b 4
b 6
b .
;

 


proc sql;
create table aa as select distinct x from a;
select distinct x into :n_1-:n_&sqlobs from a;
quit;
%let N = &sqlobs;
%macro headache;
%do i=1 %to &N;
%put &&n_&i;
proc sql;
create table report as select score from a where x="&&n_&i";
quit;
data re;
set report;
sn+1;
run;
title "report for &&n_&i";
ODS PDF FILE="D:\Practice\test.pdf";
proc report data=re nowd;
column sn score;
define sn /order ;
define score/style(column)={just=left};
run;
ods _all_ close;
%end;
%mend;
%headache;

 

So ideally this should print two pages in output but it print only single page and that is for last subject only.

 

I have observed that macro is overwriting the observations.Please guide.

Contributor
Posts: 24

Re: Proc Report-One subject data per page

Hi,

 

Can anyone please guide and tweak the attached code for me.

 

In this, Proc report is overwriting previous subject observation and poduce only one page.

 

I need two page in that report

Super Contributor
Posts: 394

Re: Proc Report-One subject data per page

In your macro, the statement

ODS PDF FILE="D:\Practice\test.pdf"

recreates test.pdf every time the macro is called. That means each time you call the macro the macro overwrites the previous version of the file. Remove this statement from your macro and put it just before you run the macro.

Contributor
Posts: 24

Re: Proc Report-One subject data per page

Thanks Tom,

I have placed the same outside macro but now it write only first observation .

I also tried to place it inside macro but before do loop and it writes last observatioon .
Super User
Posts: 10,483

Re: Proc Report-One subject data per page

[ Edited ]

You may want to look at BY processing with the #BYLINE and #BYVAL to modify the title.

 

 

Ask a Question
Discussion stats
  • 7 replies
  • 351 views
  • 0 likes
  • 3 in conversation