Hello experts,
I am using proc sgplot to graph and sending my output, which is multiple graphs in one page to PDF, however, when I run the code the graphs are placed vertically instead of horizontally. I am obviously doing something wrong. Please see my code below.
ods _all_ close;
ods pdf file="&path/tasks/stl_conf/conf_new/report9.pdf" style=calibri startpage=never notoc dpi=300;
ods graphics / reset=all height=3in width=4in;
ods layout gridded columns=2;
proc sgplot data=hist2.pop_by_age1 noautolegend;
styleattrs datacolors=(BIB VLIGB) datacontrastcolors=(gray);
vbarparm category=Age_group response=Delta_Age /group=group groupdisplay=cluster fillpattern
limitlower=L_Age limitupper=U_Age limitattrs=(color=vipr);
title 'Change by Age';
yaxis label='change';
xaxis label='Age';
run;
proc sgplot data=hist2.age25_above1 noautolegend;
styleattrs datacolors=(BIB VLIGB) datacontrastcolors=(gray);
vbarparm category=educational_attainment response=Delta_25_above / group=group groupdisplay=cluster fillpattern
limitlower=L_Ed limitupper=U_Ed limitattrs=(color=vipr);
title "Change by Educational attainment for 25 Years and Above";
yaxis label='change';
xaxis label='Level of educational attainment';
run;
ods pdf close;
ods preferences;
ods layout end;
Did you try changing your graph sizes.
A page is 8.5x11 and your graphs are 4 inches wide so that is likely causing issues. You also want to move some lines of your code around - layout end should go before ODS PDF CLOSE most likely.
Try this, instead of layout, use the columns option on ODS PDF statement.
ods _all_ close;
ods pdf file="&path/tasks/stl_conf/conf_new/report9.pdf" style=calibri startpage=never notoc dpi=300 columns=2;
ods graphics / reset=all height=3in width=4in;
proc sgplot data=hist2.pop_by_age1 noautolegend;
styleattrs datacolors=(BIB VLIGB) datacontrastcolors=(gray);
vbarparm category=Age_group response=Delta_Age /group=group groupdisplay=cluster fillpattern
limitlower=L_Age limitupper=U_Age limitattrs=(color=vipr);
title 'Change by Age';
yaxis label='change';
xaxis label='Age';
run;
proc sgplot data=hist2.age25_above1 noautolegend;
styleattrs datacolors=(BIB VLIGB) datacontrastcolors=(gray);
vbarparm category=educational_attainment response=Delta_25_above / group=group groupdisplay=cluster fillpattern
limitlower=L_Ed limitupper=U_Ed limitattrs=(color=vipr);
title "Change by Educational attainment for 25 Years and Above";
yaxis label='change';
xaxis label='Level of educational attainment';
run;
ods pdf close;
If you want to stick with layout try changing your graph sizes to see if they go side by side. If they do, I think you need to then adjust your margins to make sense.
@michokwu wrote:
Hello experts,
I am using proc sgplot to graph and sending my output, which is multiple graphs in one page to PDF, however, when I run the code the graphs are placed vertically instead of horizontally. I am obviously doing something wrong. Please see my code below.
ods _all_ close; ods pdf file="&path/tasks/stl_conf/conf_new/report9.pdf" style=calibri startpage=never notoc dpi=300; ods graphics / reset=all height=3in width=4in; ods layout gridded columns=2; proc sgplot data=hist2.pop_by_age1 noautolegend; styleattrs datacolors=(BIB VLIGB) datacontrastcolors=(gray); vbarparm category=Age_group response=Delta_Age /group=group groupdisplay=cluster fillpattern limitlower=L_Age limitupper=U_Age limitattrs=(color=vipr); title 'Change by Age'; yaxis label='change'; xaxis label='Age'; run; proc sgplot data=hist2.age25_above1 noautolegend; styleattrs datacolors=(BIB VLIGB) datacontrastcolors=(gray); vbarparm category=educational_attainment response=Delta_25_above / group=group groupdisplay=cluster fillpattern limitlower=L_Ed limitupper=U_Ed limitattrs=(color=vipr); title "Change by Educational attainment for 25 Years and Above"; yaxis label='change'; xaxis label='Level of educational attainment'; run; ods pdf close; ods preferences; ods layout end;
Thanks for the feedback. Cynthia's option worked.
Thank you!
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.