BookmarkSubscribeRSS Feed
P_S_
Obsidian | Level 7

Hi All,

This is my first attempt to use Proc Document while still preserving the ODS Layout in my PDF Output Destination.

I am using SAS 9.3. For this example I am using sashelp.stocks dataset.

Here is what I am trying to achieve:

I want 3 plots in each page.

1st page will have 1 column and 3 plots.

2nd page has 2 columns: Column 1 has 2 plots & Column 2 has 1 plot.

I was able to achieve it with the code below using ODS Gridded Layout but I want to preserve this layout when I use PROC DOCUMENT Later on.

/*This codes gives me the layout I want*/
%macro plot_stocktrend(company);

ods graphics on /height=4in width=5in border=on;

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "&company.")) description= "Stock Trend : &company";;

title "Stock Trend : &company";

series x=date y=close;

series x=date y=low;

series x=date y=high;

run;

title;

%mend plot_stocktrend;

%macro plot_volume(company);

  proc sgplot data=sashelp.stocks (where=(date >= "01jan2000"d

                                    and date <= "01jan2001"d

                                   and stock = "&company.")) description= "Stock Volume : &company";;

  title "Stock Volume vs. Close : &company.";

vbar date  /response=volume;

vline date /response=close y2axis;

run;

title;

%mend plot_volume;

title;

goptions reset=goptions device=sasprtc target=sasprtc ftext='Arial' ftitle='Arial/bold' ;

options orientation = portrait papersize = letter nodate nonumber;

ods _all_ close;

ods noproctitle;

ods pdf file     ="~/gridded_layout.pdf"  pdftoc=1 startpage=never;

ods layout gridded columns=1 rows=3 row_heights = (3in 3in 3in ) row_gutter=.5in;

  ods region height = 3in ;

  %plot_stocktrend(IBM);

  ods region height = 3in;

  %plot_stocktrend(Intel);

  ods region height = 3in;

  %plot_stocktrend(Microsoft);

  ods layout end;

  ods pdf startpage=now;

  ods layout gridded columns=2 rows=3 row_heights = (3in 3in 3in ) row_gutter=.5in;

  ods region height = 3in ;

  %plot_volume(IBM);

  ods region height = 3in;

  %plot_volume(Intel);

  ods region height = 3in;

  %plot_volume(Microsoft);

  ods layout end;

  ods pdf close;


OUTPUT:

PAGE 1


This example has just 6 plots arranged in 2 pages. But in reality I have over 150 plots that I need to output to PDF.
Thus in my PDF, I also need a good bookmark so that it will be easy to navigate the plots.

To achieve that I want to use ODS Document Destination and Proc Document. But at the same time I want to preserve my original layout that I have shown above.

I have used the code below. This creates a good navigation panel. But the layout is not preserved. It outputs one plot in each page. I need to modify this code so that I can somehow  use my ODS Gridded Layout statement.

If there is any other techniques to achieve this, I would be happy to use that as well.

Please advise.

ods document name=mydocument(write);

  %plot_stocktrend(IBM);

  %plot_stocktrend(Intel);

  %plot_stocktrend(Microsoft);

   %plot_volume(IBM);

  %plot_volume(Intel);

  %plot_volume(Microsoft);

  ods document close;

proc document name=mydocument;

list / levels=all;

run;

proc document name=mydocument;

  make trend,volume;

setlabel \trend#1  "Stock Trend";

setlabel \volume#1 "Stock Volume";

copy \Sgplot#1\SGPlot#1 to \trend#1;

copy \Sgplot#2\SGPlot#1 to \trend#1;

copy \Sgplot#3\SGPlot#1 to \trend#1;

  copy \Sgplot#4\SGPlot#1 to \volume#1;

  copy \Sgplot#5\SGPlot#1 to \volume#1;

  copy \Sgplot#6\SGPlot#1 to \volume#1;

  run;

quit;

title;

  goptions reset=goptions device=sasprtc target=sasprtc ftext='Arial' ftitle='Arial/bold' ;

  options orientation = portrait papersize = letter nodate nonumber;

  ods _all_ close;

  ods noproctitle;

  ods pdf file     ="~/gridded_layout_w_doc.pdf"  pdftoc=1;

  proc document name=mydocument;

  replay \trend#1;

  replay \volume#1;

  run;

  quit;

  ods pdf close;

RESULTS:

  • Navigation Panel is exactly what I need.
  • But plots are one per page.
1 REPLY 1
ballardw
Super User

I think you can use the ODS PDF Bookmarkgen=ON ; ODS PDF Bookmarkgen=OFF; to toggle at selected points in you code whether to create a bookmark or not.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 9011 views
  • 0 likes
  • 2 in conversation