DATA Step, Macro, Functions and more

Sgplot title and size

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 94
Accepted Solution

Sgplot title and size

When I set the path and file name in this code and run it, plot 1 (using gplot) comes out to occupy the entire page on the pdf, but plot 2 (using sgplot) is smaller, how did this happen without me changing the graph size, and can I keep plot 2 the same size as plot 1? I would like to have the size of plot 1 be the default size.

Also, plot 2 does not have the specified title in the saved pdf, how to correct that? Basically, how can I use proc sgplot to get the same result as the proc gplot in this code ?Thanks.

 

data raw;
set sashelp.cars;
keep invoice enginesize;
run;

/*define path and pdf name*/
ods pdf file=".../...pdf";

/*plot 1*/
goptions reset=all border;
symbol1 interpol=none value=dot;
title "enginze size and invoice, plot 1";
axis1 label=('engine size') ;
axis2 label=(angle=90 'invoice') ;

proc gplot data=raw;
plot invoice*enginesize / overlay haxis=axis1 vaxis=axis2 ;
run;

/*plot 2*/
proc sgplot data=raw;
	scatter x=enginesize y=invoice;
	xaxis label='engine size';
	yaxis label='invoice';
	title "enginze size and invoice, plot 2";
run;


ods pdf close;


Accepted Solutions
Solution
a month ago
Super User
Posts: 23,749

Re: Sgplot title and size

Posted in reply to apolitical

What is the best way to suppress ODS output in SAS?

https://blogs.sas.com/content/iml/2015/05/26/suppress-ods.html

 

 

 

View solution in original post


All Replies
Super User
Posts: 23,749

Re: Sgplot title and size

Posted in reply to apolitical

 

You used different PROCS (GPLOT vs SGPLOT) which have different default settings so you get different results. I would recommend sticking with the same procedure family (SG) over SAS/GRAPH or explicitly setting your graph sizes. GOPTION settings do not affect SG procedures, most settings can be found under ODS GRAPHICS, or the size option at least.

 


@apolitical wrote:

When I set the path and file name in this code and run it, plot 1 (using gplot) comes out to occupy the entire page on the pdf, but plot 2 (using sgplot) is smaller, how did this happen without me changing the graph size, and can I keep plot 2 the same size as plot 1? I would like to have the size of plot 1 be the default size.

Also, plot 2 does not have the specified title in the saved pdf, how to correct that? Basically, how can I use proc sgplot to get the same result as the proc gplot in this code ?Thanks.

 

data raw;
set sashelp.cars;
keep invoice enginesize;
run;

/*define path and pdf name*/
ods pdf file=".../...pdf";

/*plot 1*/
goptions reset=all border;
symbol1 interpol=none value=dot;
title "enginze size and invoice, plot 1";
axis1 label=('engine size') ;
axis2 label=(angle=90 'invoice') ;

proc gplot data=raw;
plot invoice*enginesize / overlay haxis=axis1 vaxis=axis2 ;
run;

/*plot 2*/
proc sgplot data=raw;
	scatter x=enginesize y=invoice;
	xaxis label='engine size';
	yaxis label='invoice';
	title "enginze size and invoice, plot 2";
run;


ods pdf close;


 

Frequent Contributor
Posts: 94

Re: Sgplot title and size

I also want to run a regression and save the results in my pdf. When I turn on ods graphics on and set the size, and run the following code, there are a number of additional generated tables saved in my pdf. This was not a problem before, or if you set ods graphics to off. How can I both set the ods graphics size and suppress these small tables from my pdf?

 

Also the graph title still isn't there. Thanks.

 


data raw;
set sashelp.cars;
keep invoice enginesize;
run;

/*define path and pdf name*/
ods pdf file="...pdf";

/*set graph size, but this saved the small tables I don't want in my pdf*/
ods graphics on / width=9in;
/*turn off ods graphics, but it does not allow changing graph size*/
/*ods graphics off;*/


/*regression, i only want to save the results tables on the first page, but not the small charts following that*/
ods output FitStatistics = fitstats;
proc reg data=raw outest=param tableout;
model invoice=enginesize ;
output out=reg_out p=predicted r=residual /*residual is actual - predicted values*/;
run;

/*plot 2*/
proc sgplot data=raw;
	scatter x=enginesize y=invoice;
	xaxis label='engine size';
	yaxis label='invoice';
	title "enginze size and invoice, plot 2";
run;


ods pdf close;

Solution
a month ago
Super User
Posts: 23,749

Re: Sgplot title and size

Posted in reply to apolitical

What is the best way to suppress ODS output in SAS?

https://blogs.sas.com/content/iml/2015/05/26/suppress-ods.html

 

 

 

Frequent Contributor
Posts: 94

Re: Sgplot title and size

Thank you that worked. Putting these two lines before proc reg helps get what I want. It's a little strange to me that without ods anything proc reg does not show tables on diagnostics and residual/fit plots in the output, but as as soon as you specify you just want one thing (fit statistics), it spits out everything together, and you have to add another command to remove the things you don't want. 

 

ods output FitStatistics = fitstats;
ods exclude DiagnosticsPanel ResidualPlot FitPlot;
Frequent Contributor
Posts: 94

Re: Sgplot title and size

Posted in reply to apolitical
Also, adding "ods _all_ close" in front allows saving graph titles into the pdf file, found here:
https://communities.sas.com/t5/SAS-Enterprise-Guide/ODS-PDF-SGPLOT-missing-title/td-p/394225
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 92 views
  • 0 likes
  • 2 in conversation