I am trying to create multiple PDF files with each one more more pages. The code that I am trying to use is shown below. If the ID in the data changes, a new PDF file should be generated, if it is the same as its lag, a new PDF page should be appended to the previously opened PDF. Running the code, all pages seem to append to the first opened pdf file, without pagebreaks in between (even though I have specified ods startpage = now). The macro %print_data consists of some analysis and some report generating, a general structure can be seen below (there is a bit more to it, but in general that's all it does). I hope someone can help me fix my program to get the desired outcome. data _null_;
set dataset;
lag_id = lag(id);
if lag_id ne id then
do;
ods pdf close;
*Generate new PDF!;
call symput('filename',id_name);
ods pdf file="C:\&filename..pdf'" startpage=never;
call execute('%nrstr(%print_data('||column1||','||column2||'))');
end;
else
do;
*Append to previously opened PDF. Create new page;
ods pdf startpage=now;
call execute('%nrstr(%print_data('||column1||','||column2||'))');
end;
run; %macro print_data(key1,key2);
ods graphics off; /* or use the %ODSOff macro */
ods exclude all; /* suspend all open destinations */
data prep;
set full-database;
where id_key1 = &key1.;
run;
ods exclude none; /* or use the %ODSOn macro */
ods graphics on / height=8cm;
proc print data=prep;
run;
%mend;
... View more