SAS Proc PDF无法导出文件。

huangapple go评论55阅读模式
英文:

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:

  1. 输出文件位置应该用双引号括起来。单引号无法解析宏变量。
  2. 在输出文件夹和输出文件名之间缺少 \

正确的行应该是:

    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:

  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 ;

答案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=&quot;c:\temp\class-byname-.pdf&quot; 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&lt;n&gt; and have the by variable value become part of the output filename.

huangapple
  • 本文由 发表于 2023年5月24日 21:22:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定