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;

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
  • 1575 views
  • 0 likes
  • 4 in conversation