sasods

sas proc pdf doesn't export the files


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 ;

Solution

  • 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 ;