0
votes

I have written a SAS macro that imports all the excel files in a folder and it works. What I want to do next is - send the proc import logs or results for all the excel files to a single pdf. My SAS code looks like this:

%macro readxls (copyfrom=);
---
---
---
%do i=1 %to $count_files;
ods listing close;
ods pdf file='pathname\report_import.pdf';
proc import datafile="&copyfrom.\...." out=copyto.... DBMS=xlsx replace;
getnames=yes; 
run;
ods pdf close;
ods listing;
%end;
%mend readxls;

For some reason, no pdf file gets generated. And the SAS log says, "NOTE: Writing ODS PDF output to DISK destination "pathname\report_import.pdf", printer "PDF"

1

1 Answers

3
votes

You cannot redirect the log directly to an ODS output destination. The import procedure has no output that is send to an ODS destination.

What you can do is redirect the log to a textfile using PROC PRINTTO. Next you can import the file using PROC DOCUMENT and write it to an ODS output destination using the replay function.

filename pdflog 'pathname\report_import.pdf';
filename tmplog 'pathname\report_import.txt';

proc printto log=tmplog;run;

%macro readxls (copyfrom=);

%do i=1 %to $count_files;
proc import datafile="&copyfrom.\...." out=copyto.... DBMS=xlsx replace;
getnames=yes; 
run;
%end;

%mend readxls;

%readxls(copyfrom=...);

proc printto;run;

proc document name=pdflog(write);
   import textfile=tmplog to logfile;
run; 

ods listing close;

ods pdf file=pdflog notoc;
 replay; 
 run;
ods pdf close;

quit;

ods listing close;