You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为SAS宏循环生成的PDF图表添加自定义书签?

Fixing Generic PDF Bookmarks for SAS GPlots (Simple Solution)

I get it, those default bookmarks from PROC GPlot are way too vague. The good news is you can add custom, descriptive bookmarks with just a few lines added to your existing macro—no complicated PROC REPORT workarounds required.

Modified Full Code

data out_i_a; set sashelp.retail; run;
data out_ii_b; set sashelp.retail; run;
data y; length saz tef $100; input saz $ tef $; datalines; i a ii b ; run;
%macro grafy();
proc sql; select count(*) into: pocet from y; quit;
ods _all_ close;
goptions hsize=20cm vsize=8cm;
ods pdf file="\\srv05\\nt05a\\GRAF\\TOT_testing.pdf";
ods layout gridded columns=1;
%do i=1 to &pocet;
data _null_; set y (obs=&i); call symput("saz" ,strip(saz)); call symput("tef" ,strip(tef)); run;
ods region;
ods pdf text="&saz._&tef";

/* Add custom bookmark for first plot */
ods pdf bookmark="&saz._&tef. - Sales & Year by Date";
symbol1 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=1 CV= _STYLE_;
symbol2 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=1 CV= _STYLE_;
Legend1 value=('SALES' 'YEAR');
axis1 label=('# sales'); axis3 label=('# year'); axis2 label=('date');
proc gplot data= out_&saz._&tef;
plot (SALES)*DATE / overlay skipmiss VAXIS=AXIS1 HAXIS=AXIS2 LEGEND=Legend1;
plot2 (YEAR)*DATE / overlay skipmiss VAXIS=AXIS3 HAXIS=AXIS2 LEGEND=Legend1;
run;

ods region;

/* Add custom bookmark for second plot */
ods pdf bookmark="&saz._&tef. - Year & Month by Date";
symbol1 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=1 CV= _STYLE_;
symbol2 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=2 CV= _STYLE_;
Legend1 value=('year' 'month');
axis1 label=('in %, p.a.'); axis2 label=('date');
proc gplot data= out_&saz._&tef;
plot (YEAR MONTH)*DATE / overlay skipmiss VAXIS=AXIS1 HAXIS=AXIS2 LEGEND=Legend1;
run;
%end;
ods layout end;
ods pdf close;
%mend;
%grafy();

What Changed?

  • I added an ods pdf bookmark="..." statement right before each PROC GPLOT call. This tells SAS to use your custom text as the bookmark for the upcoming plot, replacing the generic default.
  • The bookmark text uses your existing macro variables &saz and &tef plus a clear description of what the plot shows (e.g., "Sales & Year by Date"), so each bookmark is unique and informative.
  • This fits perfectly into your existing loop and ODS layout—no major code restructuring needed.

Resulting Bookmarks

After making these changes, your PDF bookmarks will look like this:

  • i_a - Sales & Year by Date
  • i_a - Year & Month by Date
  • ii_b - Sales & Year by Date
  • ii_b - Year & Month by Date

Each bookmark now clearly links to the exact dataset and plot type, making the PDF much easier to navigate.

内容的提问来源于stack exchange,提问作者jiri jansa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:43:36