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!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 937 views
  • 0 likes
  • 2 in conversation