BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michokwu
Quartz | Level 8

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; 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
Hi:
Take a look at this paper -- pages 23/24/25:
http://support.sas.com/resources/papers/proceedings16/SAS5762-2016.pdf

I think you're missing column_widths on the ODS LAYOUT statement to set the width of the columns you want the images to go in and I then I think you also need ODS REGION; statements to indicate to ODS when to move to a new region. The code model for the output is in the paper -- my output had a PROC REPORT at the top but you can ignore that part. The only other thing I would recommend is that you make sure your margins are set appropriately with a width of 4 in for each image, you're almost running out of space on a portrait page. I'd tend to do 3.75 for the column widths and 3.5 for the image widths with .25 left and right margins, should look good in 8 inches on a portrait page.
Hope this helps,
Cynthia

View solution in original post

4 REPLIES 4
Reeza
Super User

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; 

 

 


 

michokwu
Quartz | Level 8

Thanks for the feedback. Cynthia's option worked.

Cynthia_sas
SAS Super FREQ
Hi:
Take a look at this paper -- pages 23/24/25:
http://support.sas.com/resources/papers/proceedings16/SAS5762-2016.pdf

I think you're missing column_widths on the ODS LAYOUT statement to set the width of the columns you want the images to go in and I then I think you also need ODS REGION; statements to indicate to ODS when to move to a new region. The code model for the output is in the paper -- my output had a PROC REPORT at the top but you can ignore that part. The only other thing I would recommend is that you make sure your margins are set appropriately with a width of 4 in for each image, you're almost running out of space on a portrait page. I'd tend to do 3.75 for the column widths and 3.5 for the image widths with .25 left and right margins, should look good in 8 inches on a portrait page.
Hope this helps,
Cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 8217 views
  • 0 likes
  • 3 in conversation