BookmarkSubscribeRSS Feed
szzzdhrd
Fluorite | Level 6

I am using "sgplot" and making a "hbar" graph. Everything looks fine till I export it to pdf as part of a  multi-graph using "ods pdf file". The problem is with y-axis values. The values are scattered left and right.

I tried VALUESHALIGN=left and that will adjust them to the left but with a huge distance from the axis and I don't know how to get rid of it.

I also tried  VALUESHALIGN=right but that did not do anything. It did not change the values at all.

I appreciate your though on that.

 

 

 

 

6 REPLIES 6
ballardw
Super User

Code please starting from ODS PDF statement. Data to plot would be helpful as data step code.

 

Note: PDF by default uses a different ODS style so results often change from the results window appearance.

szzzdhrd
Fluorite | Level 6

Thanks for the reply. Sorry I cannot put the data here for some work reasons. 

 

title "Uni";
ods pdf file="X:\reports\Year.pdf" ;
options orientation=portrait papersize=letter topmargin=0.001in bottommargin=0.001in leftmargin=0.001in rightmargin=0.001in;
ods layout Start width=8.5in height=11in ;
ods graphics / noborder;

proc sgplot data=DFac;
ods region x=3in y=0in width=3in height=3in;
title 'Faculty Race';
hbar frace / categoryorder=respdesc datalabel;
xaxis label="Count";
yaxis label="Ethnicity" display=(nolabel noticks) valueattrs=(color=black family=arial size=6pt weight=bold ) VALUESHALIGN=left;
run;
quit;
proc sgpie data=DFac;
ods region x=0 y=22% width=45% height=20%;
title 'Faculty Sex';
styleattrs datacolors=(grey black bib);
donut fsex / holevalue /*holelabel='Count'*/ ringsize=0.5;
run;
quit;


ods layout end;
ods pdf close;

ballardw
Super User

If for no other reason then following code, it is not a good idea to place statements related to external items such as ODS LAYOUT or REGION information in the middle of a procedure like SGPLOT.

 

Rick_SAS
SAS Super FREQ

Please post a picture of what you are seeing.

Rick_SAS
SAS Super FREQ

I am certainly not an expert on the PDF destination, but try the following code to see if it give output close to what you expect:

data DFac;
call streaminit(1);
length frace $20 fsex $13;
array race [6] $20 ('White, Not Hispanic', 'Black, Not Hispanic', 'Asian', 'Not Specified', 'American Indian', 'Hawaiian');
array sex [3] $13 ('Male', 'Female', 'Not Specified');
do i = 1 to 1200;
   k = rand("table", 0.80, 0.10, 0.07, 0.01, 0.01, 0.01);
   frace = race[ k ];
   k = rand("table", 0.47, 0.48, 0.05);
   fsex = sex[ k ];
   output;
end;
keep i frace fsex;
run;

ods html close;
ods graphics / noborder;

title "Uni";
ods pdf file="Year.pdf" ;
options orientation=portrait papersize=letter topmargin=0.001in bottommargin=0.001in leftmargin=0.001in rightmargin=0.001in;
ods layout Start;

ods region x=3in y=0in width=3in height=3in;
title 'Faculty Race';
proc sgplot data=DFac;
hbar frace / categoryorder=respdesc datalabel;
xaxis label="Count";
yaxis label="Ethnicity" display=(nolabel noticks) valueattrs=(color=black family=arial size=6pt weight=bold ) VALUESHALIGN=left;
run;

ods region x=0in y=0in width=3in height=3in;
title 'Faculty Sex';
proc sgpie data=DFac;
styleattrs datacolors=(grey black bib);
donut fsex / holevalue /*holelabel='Count'*/ ringsize=0.5;
run;

ods layout end;
ods pdf close;

The most likely explanation for the misaligned labels is bad data. Since I don't have your data, I cannot test, but you ought to be able to use PROC FREQ to see whether the categories for race are correctly formatted.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 694 views
  • 0 likes
  • 3 in conversation