BookmarkSubscribeRSS Feed
madhu
Calcite | Level 5
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
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
madhu
Calcite | Level 5
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
data_null__
Jade | Level 19
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.
data_null__
Jade | Level 19
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.
Flip
Fluorite | Level 6
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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2477 views
  • 0 likes
  • 4 in conversation