Data visualization with SAS programming

How to display a listing and a graph on one PDF page

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How to display a listing and a graph on one PDF page

Hi,

I am using SAS 9.1.3, and here is the test code:

test code

goptions reset=all   ;

options orientation=portrait;

ods listing close;

ods pdf startpage=never;

ods pdf file="C:\aa.pdf" ;

** A Listing;

proc print data=sashelp.class; 

run;

** A graph;

symbol v=dot h=2 c=blue;

proc gplot data=sashelp.class;

   plot height*weight;

run;

quit;

ods pdf close;

ods listing;

And here is the result:

Capture.JPG

It seems that when creating the graph, SAS takes the whole page as the canvas and it didn't 'see' that a listing was already on the page.

Question is: is there a way to make SAS automatically display the graph right after the listing?

For example, suppose we need to create a 4inch*3inch scatterplot,

if there's a listing(PROC PRINT) before the GPLOT, then display the graph after the listing;

if there's no listing, then directly display the graph at the top of the page.

Any help will be highly appreciated, thanks!!!


Accepted Solutions
Solution
‎04-30-2015 07:26 AM
SAS Super FREQ
Posts: 703

Re: How to display a listing and a graph on one PDF page

With SAS9.4 the following code sample will do what you are after. It uses the ODS LAYOUT feature. Before each output you create you will have an ODS REGION statement, to say you are starting a new region to place output into. I might not do the exact same thing in SAS9.1.3, but have a go.

goptions reset=all   ;

options orientation=portrait;

ods _all_ close;

ods pdf startpage=never;

ods pdf file="C:\temp\aa.pdf" ;

ods layout gridded columns=1;
ods region;

** A Listing;
proc print data=sashelp.cars(obs=40);
  var make model type driveTrain invoice horsepower;
run;


ods region;
** A graph;

goptions
/*  horigin=8cm*/
/*  vorigin=8cm*/
 
hsize=8cm
 
vsize=8cm
;

symbol v=dot h=2 c=blue;
proc gplot data=sashelp.class;
   plot height*weight;
run;
quit;
ods layout end;

ods pdf close;

ods listing;

View solution in original post


All Replies
SAS Super FREQ
Posts: 703

Re: How to display a listing and a graph on one PDF page

hi

You can use the following options to control the start position and size of the graph.

goptions

  horigin=4cm

  vorigin=4cm

  hsize=14cm

  vsize=12cm

;

Please note, that the lower left corner is the zero point for the HORIGIN and VORIGIN

Contributor
Posts: 23

Re: How to display a listing and a graph on one PDF page

Thanks!

However, after the settings of HORIGIN / VORIGIN/ HSIZE / VSIZE, the graph will be on a fixed position of the page, no matter how long the listing is.

Super User
Super User
Posts: 7,682

Re: How to display a listing and a graph on one PDF page

Hi,

Your point being?  If there is a lot of data in the listing, then its going to take up more space on the page.  You could check the number of rows in the dataset being listed, then adjust your options accorindingly, e.g.:

proc sql;

     select    20 - (select NOBS from SASHELP.VTABLE where LIBNAME="WORK" and MEMNAME="THETABLE")

     into       :NUM_CM

     from     SASHELP.CLASS;

quit;

goptions horigin=&NUM_CM.cm vorigin=4cm hsize=14cm vsize=&NUM_CM.cm;


Just an untested example above.  But this only means that if the data exapnds you graph will shrink.  Paper size is fixed.  You could try listing the data with smaller font, dropping the ZOOM aspect of the graph etc. but if your data is changing/growing you will always hit this fixed paper size.

Contributor
Posts: 23

Re: How to display a listing and a graph on one PDF page

Thank you!

It's a good idea.

SAS Super FREQ
Posts: 703

Re: How to display a listing and a graph on one PDF page

This paper may also be of interest. I talks about using ODS LAYOUT to position output at specific areas on the PDF

http://analytics.ncsu.edu/sesug/2008/SIB-097.pdf

Solution
‎04-30-2015 07:26 AM
SAS Super FREQ
Posts: 703

Re: How to display a listing and a graph on one PDF page

With SAS9.4 the following code sample will do what you are after. It uses the ODS LAYOUT feature. Before each output you create you will have an ODS REGION statement, to say you are starting a new region to place output into. I might not do the exact same thing in SAS9.1.3, but have a go.

goptions reset=all   ;

options orientation=portrait;

ods _all_ close;

ods pdf startpage=never;

ods pdf file="C:\temp\aa.pdf" ;

ods layout gridded columns=1;
ods region;

** A Listing;
proc print data=sashelp.cars(obs=40);
  var make model type driveTrain invoice horsepower;
run;


ods region;
** A graph;

goptions
/*  horigin=8cm*/
/*  vorigin=8cm*/
 
hsize=8cm
 
vsize=8cm
;

symbol v=dot h=2 c=blue;
proc gplot data=sashelp.class;
   plot height*weight;
run;
quit;
ods layout end;

ods pdf close;

ods listing;
Contributor
Posts: 23

Re: How to display a listing and a graph on one PDF page

ODS LAYOUT works.

Thank you very much!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 511 views
  • 3 likes
  • 3 in conversation