I am trying to create a bar chart with the correct data labels. If I write my code like this:
DATA AgeChart; SET BCMasterSet2; FORMAT AgeGroup; IF missing(Age) then delete; IF Age < 40 then AgeGroup = 39; ELSE IF (Age > 39 & Age < 50) then AgeGroup = 49; ELSE IF (Age > 49 & Age < 60) then AgeGroup = 59; ELSE IF (Age > 59 & Age < 70) then AgeGroup = 69; ELSE AgeGroup = 70; KEEP Age AgeGroup; RUN; PROC SGPLOT DATA = AgeChart; /*xaxis values = ("<40" "40-49" "50-59" "60-69" "70>");*/ VBAR AgeGroup; run;
I get the following chart:
But I don't want the data labels as they are. I want them to say "<40", "40-49", "50-59", "60-69", and "70>".
So I typed in the above code in order to get that, removing the comment feature out of the xaxis values statement, and this is what happens to my bar chart:
Where did all my data go? Can someone help me fix this problem? Thank you!
See if this gets you close:
proc format library=work; value AgeGroup 0 - 39 = " <40" 40 - 49= "40-49" 50 - 59= "50-59" 60 - 69= "60-69" 70 - high="70>" ; run; proc sgplot data=Bcmasterset2; vbar age ; format age agegroup.; label age= 'Age Group'; run;
You can use custom formats to create groups of values as well as supply text labels for them. I use them a lot because I can have multiple similar formats and apply as needed without creating addtional variables.
The issue is that XAXIS values you provided were character and did not match values of the actual age group variable.
See if this gets you close:
proc format library=work; value AgeGroup 0 - 39 = " <40" 40 - 49= "40-49" 50 - 59= "50-59" 60 - 69= "60-69" 70 - high="70>" ; run; proc sgplot data=Bcmasterset2; vbar age ; format age agegroup.; label age= 'Age Group'; run;
You can use custom formats to create groups of values as well as supply text labels for them. I use them a lot because I can have multiple similar formats and apply as needed without creating addtional variables.
The issue is that XAXIS values you provided were character and did not match values of the actual age group variable.
proc sgplot data=sashelp.class;
vbar age;
xaxis values=('11' '12' '13' '14' '15' '16') VALUESDISPLAY=("<40" "40-49" "50-59" "60-69" "70>" "sds");
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.