BookmarkSubscribeRSS Feed
SasStatistics
Pyrite | Level 9

I have a bar chart of the following look: 

SasStatistics_0-1672759126827.png


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

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
SasStatistics
Pyrite | Level 9
The format of the variable is YYMMN4. so it should be date.
Hopefully someone knows how to do it, if not I will have to try do some replicating example since I am using data from a database that is not available straight away.
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller
ballardw
Super User

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.

 

SAS Innovate 2025: Register Now

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!

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
  • 983 views
  • 0 likes
  • 3 in conversation