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;
https://blogs.sas.com/content/iml/2015/05/26/suppress-ods.html
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;
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;
https://blogs.sas.com/content/iml/2015/05/26/suppress-ods.html
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.