I have looked everywhere and tried every solution however, I cant fix my issue.
I would like to create a bar chart and group the bars by the data. My data is attached. I have tried the xaxis discreteorder=data but
the bar order did not change. Below is my code.
proc import datafile = "filepath"
DBMS = xlsx out = graph replace ;
run;
proc sort data=graph ;
by year descending regstatusnew;
run;
title 'Test Double Bar Graph';
proc sgplot data=graph;
vbar year / response=totals stat=sum group=regstatusnew nostatlabel
groupdisplay=cluster; xaxis discreteorder=data;
xaxis display=(nolabel);
yaxis grid;
run;
I think this is what you want
data graph;
input YEAR REGSTATUSNEW :$11. TOTALS;
datalines;
2014 Participant 28.475
2015 Participant 28.132
2016 Participant 40.526
2017 Participant 28.179
2018 Participant 39.876
2019 Participant 27.195
2020 Participant 31.497
2014 Cumulative 28.475
2015 Cumulative 56.607
2016 Cumulative 97.133
2017 Cumulative 125.312
2018 Cumulative 165.188
2019 Cumulative 192.383
2020 Cumulative 223.880
;
proc sort data=graph ;
by year descending regstatusnew;
run;
title 'Test Double Bar Graph';
proc sgplot data=graph;
vbar year / response=totals stat=sum group=regstatusnew nostatlabel
groupdisplay=cluster grouporder=data;
xaxis display=(nolabel);
yaxis grid;
run;
Result:
What do you mean by group the bars by the data? How does your result differ from you desired result?
Please be specific.
On the bar chart I would like the participant bars to come first then the cumulative bar by year. For example, 2014 would have a bar for participant-28,475 and one for cumulative 28,475, 2015 would have a bar for participant-28,132 and one for cumulative-56,607.
Right now, even after sorting the bars are 2014 cumulative - 28,475 and 28,475 participant and so on.
I think this is what you want
data graph;
input YEAR REGSTATUSNEW :$11. TOTALS;
datalines;
2014 Participant 28.475
2015 Participant 28.132
2016 Participant 40.526
2017 Participant 28.179
2018 Participant 39.876
2019 Participant 27.195
2020 Participant 31.497
2014 Cumulative 28.475
2015 Cumulative 56.607
2016 Cumulative 97.133
2017 Cumulative 125.312
2018 Cumulative 165.188
2019 Cumulative 192.383
2020 Cumulative 223.880
;
proc sort data=graph ;
by year descending regstatusnew;
run;
title 'Test Double Bar Graph';
proc sgplot data=graph;
vbar year / response=totals stat=sum group=regstatusnew nostatlabel
groupdisplay=cluster grouporder=data;
xaxis display=(nolabel);
yaxis grid;
run;
Result:
Yes, this works! Thank you so much!
Anytime 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.