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

Hello SAS Friends, 

Am using SAS ver 9.4 and ODS graphics to create a stacked bar graph, output to a .ppt file.

Cannot fathom why the bars are not aligned with the x-axis text (months) and Tick Marks, note especially AUGUST and FEBRUARY are very misaligned.

There should be one bar per month, and each should align with the month name and tick marker.

The graph and dataset are attached.

Here is the code:

title h=7 j=c " Number of New Products Reported in Shortage in 2020 by Month";
%let datetime 		= 	%sysfunc(compress(%sysfunc(today(),yymmddN8.)_%sysfunc(time(),hhmm6.), ': '));
ods powerpoint file="&out\Graphs_1 &datetime..ppt" nogtitle nogfootnote;
ods graphics / width=8.0in height=8.0in; 
ods layout gridded columns=1; 
 ods region; 
proc sort	data	=	CP.DS_4_20		;	by	_Initial_Posting_Date_yr	_Initial_Posting_Date_mo	;	run	;	
 proc sgplot data=CP.DS_4_20		;
 	styleattrs datacolors=(palegreen lightblue);
	vbar _Initial_Posting_Date_mo /  response=count group=IV_n
	              datalabel datalabelattrs=(size=8.5pt)
                  seglabel /*seglabelformat=4.*/ seglabelattrs=(size=8.5pt);
xaxis display=all  LABELPOS=CENTER	LABEL="Month"	type=time ;
yaxis display=all	values=(0 to 300 by 25)LABELPOS=CENTER	LABEL="No. Products";
keylegend / 		title="" 		/*location=inside*/ 	position=bottom noborder;
format count 4.0	_Initial_Posting_Date_mo	monname3.;
run;
ods layout end; 
ods powerpoint close;

ODS _ALL_ CLOSE ;

 

Had to provide the .PPT file as a .PDF file , so could be uploaded here.

Any and all suggestions are welcomed, 

Thank you so much 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @rmacarthur,

 

I think you need type=discrete in the XAXIS statement rather than type=time. The latter uses the actual date values of variable _Initial_Posting_Date_mo, hence the variation (of the bar positions) between months. The discrete axis type should work for your sample data in conjunction with the monname3. format because all date values are from the same year.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @rmacarthur,

 

I think you need type=discrete in the XAXIS statement rather than type=time. The latter uses the actual date values of variable _Initial_Posting_Date_mo, hence the variation (of the bar positions) between months. The discrete axis type should work for your sample data in conjunction with the monname3. format because all date values are from the same year.

rmacarthur
Pyrite | Level 9

Yes, that worked, Thanks !

Was also thinking about creating a different Month Variable, one that for any month_year combination, would return the 15th (middle) of the respective month.  But your solution is much better, thanks !

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 2 replies
  • 1188 views
  • 1 like
  • 2 in conversation