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
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.
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.
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 !
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!
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.