英文:
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;
英文:
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 ;
答案1
得分: 1
Sure, here are the translated parts:
- 输出文件位置应该用双引号括起来。单引号无法解析宏变量。
- 在输出文件夹和输出文件名之间缺少
\
。
正确的行应该是:
FILE = "&Folder.\Bakara_&b_number..pdf" STYLE = ocean ;
已更正的代码:
%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 ;
英文:
Two issues:
- The output file location should be in double quotes. Single quotes do not resolve macro variables.
- 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 ;
答案2
得分: 0
如果您的解决方案允许使用带编号的文件名,您可以使用 ODS
选项 NEWFILE=BYGROUP
。
示例:
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;
理想情况下,SAS 将改进 NEWFILE 交互以允许使用 #BYVAL<n>
指定文件名,并使按变量值分组的值成为输出文件名的一部分。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论