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
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 can you post some sample data for us to work with? Makes it easier to provide a usable code answer.
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
And you want 1 plot for each continent, correct?
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;
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.
Add
categoryorder=respdesc
after the / in the HBAR Statement.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.