The SAS Output Delivery System and reporting techniques

To print all datasets in a library

Reply
Contributor
Posts: 27

To print all datasets in a library

I am using the following macro to print all the datasets ina library to single RTF file. However only the last available dataset is being printed in the RTF. Can any one suggest any modifications so that all the datasets are printed.

%macro printall(libname);
%local num i;
proc datasets library=&libname memtype=data nodetails;
contents out=temp1(keep=memname) data=_all_ noprint;
run;
data _null_;
set temp1 end=final;
by memname notsorted;
if last.memname;
n+1;
call symput('ds'||left(put(n,8.)),trim(memname));
if final then call symput('num',put(n,8.));
run;
%do i=1 %to #

ODS Listing Close;
ods rtf nogtitle file="C:\report1.rtf" style=profile ;

proc print data=&libname..&&ds&i noobs;
run;
ods rtf close;

%end;
%mend printall;

thanks in advance
Super Contributor
Super Contributor
Posts: 3,174

Re: To print all datasets in a library

Sugest you run your code with the following SAS statement to get the most diagnostic info generated for self-checking:

OPTIONS SOURCE SOURCE2 MACROGEN MPRINT;

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 27

Re: To print all datasets in a library

The log generated by using the above mentioned options or without using the above mentioned options is clear from any warnings or errors. The problem here is once the second dataset is printed the first dataset is being replaced. I want to avoid such a replacement.

Thanks.
Super Contributor
Super Contributor
Posts: 3,174

Re: To print all datasets in a library

Suggest moving your ODS commands (plural) to be outside your %DO %END loop, which is causing the reported condition, I believe. Message was edited by: sbb
Respected Advisor
Posts: 3,799

Re: To print all datasets in a library

All you need to do is move the ODS statement outside the %DO I=1 loop so that the file remains open for all the PROC PRINTs. Then CLOSE it after you have written everything you want to it.
Respected Advisor
Posts: 3,799

Re: To print all datasets in a library

All you need to do is move the ODS statement outside the %DO I=1 loop so that the file remains open for all the PROC PRINTs. Then CLOSE it after you have written everything you want to it.
Super Contributor
Posts: 359

Re: To print all datasets in a library

Posted in reply to data_null__
One of my favorite interview questions back when I did a lot of hiring. You don't even need a macro. The ODS steps could be outside the data _null_


data _null_;
set sashelp.vmember( where = (libname = upcase('&libname') and memtype = 'DATA')) end = eof;
if _n_ = 1 then call execute("ODS Listing Close; ods rtf nogtitle file='C:\report1.rtf' style=profile ;");
call execute("proc print data = " || memname || " noobs; run;");
if EOF then call execute("ods rtf close;");
run;
Ask a Question
Discussion stats
  • 6 replies
  • 291 views
  • 0 likes
  • 4 in conversation