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

Hi

I am trying to create a simple graph with age group and gender but somehow it is not working.

This is my code and the graph. I do not understand why it is spliting my age groups

Proc format;
Value agef
65-69 = 'Age 65-69'
70-79 = 'Age 70-79'
81-84 = 'Age 81-84'
;
run;
Data newfinal;
Set FINAL;
Format age agef. Region reg.;
run;
 
 
 
axis1 label=('Number of People')
 minor=(number=1)
 offset=(0,0);
 
 /* Define legend characteristics */
legend1 label=none value=('Men' 'Women');
 
 /* Chart the values of AGE */
proc gchart data=newfinal;
hbar age / subgroup=gender
 legend=legend1
 autoref
 clipref
 coutline=black
 raxis=axis1;
run;
 
 /* Add order= to response axis */
 axis1 order=(0 to 24 by 2)
 label=('Number of People')
 minor=(number=1)
 offset=(0,0);
 
 /* Modify midpoint axis label*/
 axis2 label=('Age' j=r 'Group')
 
 /* Create chart */;
hbar3d age /
 
 freq
 freqlabel='Total in Group'
 subgroup=gender
 autoref
 maxis=axis2
 raxis=axis1
 legend=legend1
 coutline=black
       width=3.5
 space=2;
run;
quit;
 
Mscarboncopy_0-1724941966121.png

 

all numeric but I formatted the age to be able to show in the graph - might be what is causing the issue, the original data is numeric with the actual age of each participant.

ID Agegender 
   
1Age 70-792
2Age 65-691
3Age 65-692
4Age 81-841
5Age 65-691
6Age 65-692
7Age 81-842
8Age 81-842
9Age 81-842
10Age 65-692
11Age 65-692
12Age 70-791
13Age 65-692
14Age 65-692
15Age 70-791
16Age 65-692
17Age 70-792
18Age 65-692
19Age 70-792
20Age 65-691
21Age 81-842
22Age 65-692
23Age 70-792
24Age 65-692

Thank you!!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Try

axis2 label=('Age' j=r 'Group')
         order=(1 2 3)
;

That 1.5 and 2.5 tell me that your data is not actually using the age format that you displayed which would be using values more like 65 70 and 81. 

View solution in original post

6 REPLIES 6
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

I think you have observations with an age of 80, which is not covered in your format statement. Thus, the unformattted value is being displayed for that age. 

PaigeMiller
Diamond | Level 26

PROC GCHART picks its own levels for the Y-axis, and I'm guessing it has picked levels that are 5 units apart. If you want your own levels to be used, as you did in AXIS1 (for the x-axis), use the ORDER option for AXIS2.

--
Paige Miller
Mscarboncopy
Pyrite | Level 9

I figured it out. It was my variable formatting.

 

Now what I can't figure out is how to remove these tick mark on the Age axis. I do not need the 1.5 or 2.5. This is being generated in the code I shared and I cannot figure out how to change it. Thank you again.

Mscarboncopy_0-1724947023982.png

 

 

ballardw
Super User

Try

axis2 label=('Age' j=r 'Group')
         order=(1 2 3)
;

That 1.5 and 2.5 tell me that your data is not actually using the age format that you displayed which would be using values more like 65 70 and 81. 

Mscarboncopy
Pyrite | Level 9

One last thing. How do I make all of these labels a little bigger on each of the axis?

Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 656 views
  • 2 likes
  • 4 in conversation