BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
luvscandy27
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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:

 

 

sgplot.PNG

 

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

What do you mean by group the bars by the data? How does your result differ from you desired result?

 

Please be specific.

luvscandy27
Quartz | Level 8

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. 

PeterClemmensen
Tourmaline | Level 20

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:

 

 

sgplot.PNG

 

luvscandy27
Quartz | Level 8

Yes, this works! Thank you so much!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1238 views
  • 0 likes
  • 2 in conversation