sas proc pdf doesn't export the files

144 views Asked by At

I am trying to export to a specific location a set of about 15 PDF files, using the ODS PDF. While using the same code but exporting with ODS EXCEL - I get excellent results. With the ODS PDF - I get no results.

INITIAL PROC:

PROC SQL ;
SELECT DISTINCT BId INTO: B_List separated by ' '
FROM work.Pop ;
QUIT ;

THIS IS THE CODE WITH ODS EXCEL:

%MACRO Export_Excel ;
%DO i = 1 %TO 15 ;
    %LET b_number = %SCAN(&B_List., &i.) ;
    
    PROC EXPORT DATA=work.Final_Pop (WHERE=(BId = &b_number .))
    OUTFILE="&Folder.\Report&b_number ..xlsx"
    DBMS=XLSX REPLACE ;
    SHEET=b_&b_number . ;
    RUN ;
%END ;
%MEND Export_Excel ;

THIS IS THE CODE WITH ODS PDF:

%MACRO Export_PDF ;
%DO i = 1 %TO 15 ;
    %LET b_number = %SCAN(&B_List., &i.) ;
    ODS PDF
    FILE ='&Folder.Bakara_&b_number..pdf' STYLE = ocean ;
    ODS PDF TEXT = "TEST_&b_number." ;
    PROC PRINT DATA=work.Final_Pop (WHERE=(BId = &b_number.)) NOOBS ;
    RUN ;
    ODS PDF CLOSE ;
%END ;
%MEND ;
2

There are 2 answers

0
Stu Sztukowski On BEST ANSWER

Two issues:

  1. The output file location should be in double quotes. Single quotes do not resolve macro variables.
  2. are missing a \ in-between the output folder and the output file name.

The correct line should be:

FILE = "&Folder.\Bakara_&b_number..pdf" STYLE = ocean ;

Corrected code:

%MACRO Export_PDF ;
%DO i = 1 %TO 15 ;
    %LET b_number = %SCAN(&B_List., &i.) ;
    ODS PDF
    FILE = "&Folder.\Bakara_&b_number..pdf" STYLE = ocean ;
    ODS PDF TEXT = "TEST_&b_number." ;
    PROC PRINT DATA=work.Final_Pop (WHERE=(BId = &b_number.)) NOOBS ;
    RUN ;
    ODS PDF CLOSE ;
%END ;
%MEND ;
0
Richard On

If your solution allows for numbered filenames you can use the ODS option NEWFILE=BYGROUP

Example:

data c;
  set sashelp.class;
  letter = substr(name,1,1);
run;

ods pdf file="c:\temp\class-byname-.pdf" newfile=bygroup;

proc print noobs data=c;
  by letter;
  var name age sex height weight;
run;

ods pdf close;

Ideally, SAS will improve the NEWFILE interaction to allow the filename to be specified with #BYVAL<n> and have the by variable value become part of the output filename.