I have a bar chart of the following look:
produced with the following code:
PROC GCHART DATA=MyData
;
VBAR
year_month
/
SUMVAR=count
SUBGROUP=segment
CLIPREF
FRAME TYPE=SUM
LEGEND=LEGEND1
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
LREF=1
CREF=BLACK
AUTOREF
;
run;
quit;
Any ideas on how I can produce the same bar chart BUT with the horizontal axis for each month (not midpoint of multiple months).
No idea unless we can see your data that goes into this bar chart, although I am guessing that your variable year_month is not really a SAS date value. Please provide a portion of the data as WORKING data step code.
data fake;
do month = 1 to 16;
date=intnx('month','01JAN2020'd,month,'b');
count=round(rand('uniform',0,100));
type='Mammal';
output;
count=round(rand('uniform',0,100));
type='Lizard';
output;
end;
format date yymmn4.;
run;
proc sgplot data=fake;
vbar date/group=type response=count groupdisplay=stack;
run;
Unfortunately with the very old GCHART procedure you have to show us the definitions of any AXIS, SYMBOL or Pattern statements you are using.
The AXIS1 definition controls the values of your horizontal axis from the code you show. To change the VALUES displayed for the tickmarks you would need to modify that definition with an ORDER= showing the values that you want.
Perhaps: Order=('01JAN2021'd to '01Jan2023'd by month)
Your months should indicate the dates, as a date literal as shown above, for the months that you want displayed. One of the nice things with SAS and use of actual date values is the option to use the BY <interval name> option to indicate the first of the month, quarter, year or what have you (time and datetime values allow other intervals like hour).
Or in the example that @PaigeMiller a similar XAXIS statement:
xaxis values=('01JAN2021'd to '01Jan2023'd by month)
The Xaxis and Yaxis statements in the newer, usually much more flexible Sgplot, control the appearance of the axis instead of the remote often forgotten AXISn statements.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.