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

Hi, 

I have a data set which includes city, continent and average. Now I want to plot a hbar to show the average of each city across different continents with height=2200.

 

The result should be something like the attached document.

 

My approach code is 

 

proc sgplot data=have;
hbar cities / response=average;
run;

 

But I have no idea how to make it across the continent.

Please help me if you have an idea.

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

See if this gets you going.

 

data have;
input city $ 1-21 Average continent $ 25-33;
datalines;
Tirana, Albania      83 Europe
Yerevan, Armenia     90 Asia
Brisbane, Australia  35 Australia
Melbourne, Australia 31 Australia
Perth, Australia     34 Australia
;

proc sort data=have;
    by continent;
run;

proc sgplot data=have;
    by continent;
    hbar city / response=Average colorresponse=Average colormodel=(green gold red);
run;

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

@YangYY can you post some sample data for us to work with? Makes it easier to provide a usable code answer.

YangYY
Quartz | Level 8

city                                         Average                                  continent

Tirana, Albania                      83                                                Europe

Yerevan, Armenia                 90                                                 Asia

Brisbane, Australia               35                                                 Australia

Melbourne, Australia            31                                                 Australia

Perth, Australia                    34                                                  Australia

   

 

 

 

Thank you so much
 

PeterClemmensen
Tourmaline | Level 20

And you want 1 plot for each continent, correct?

YangYY
Quartz | Level 8
Yes,exactly.
PeterClemmensen
Tourmaline | Level 20

See if this gets you going.

 

data have;
input city $ 1-21 Average continent $ 25-33;
datalines;
Tirana, Albania      83 Europe
Yerevan, Armenia     90 Asia
Brisbane, Australia  35 Australia
Melbourne, Australia 31 Australia
Perth, Australia     34 Australia
;

proc sort data=have;
    by continent;
run;

proc sgplot data=have;
    by continent;
    hbar city / response=Average colorresponse=Average colormodel=(green gold red);
run;
YangYY
Quartz | Level 8

Thank you so much!

It works good. And I also wondering can I arrange them from more to less in each plot?

 

I have tried to sort the data by average before the proc sgplot but it doesn't work.

PeterClemmensen
Tourmaline | Level 20

Add 

 

categoryorder=respdesc

after the / in the HBAR Statement.

YangYY
Quartz | Level 8
Thank you!!

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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