BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
davidjayjackson
Fluorite | Level 6

Hey,

When I run the code below, the barplot is not shorting by city name and not city_count. Thanks David

 

libname party xlsx "/home/u64077777/My SAS File/Party.xlsx";


proc sql;
	drop table invites_summary;
	CREATE TABLE invites_summary AS
	SELECT City,count(*) as city_count
		FROM Party.contacts
		GROUP BY City;
quit;

proc sort data=invites_summary out=sorted_invites_summary;
    by descending city_count;
run;

proc sgplot data=sorted_invites_summary;
    hbar City / response=city_count;
    xaxis label="City";
    yaxis label="Number of People Invited";
run;
 
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you want the the plot to be sorted by the Response variable value you use the option CATEGORYORDER with either RESPASC or RESPDESC to order in response variable ascending or descending order respectively.

 

proc sgplot data=sorted_invites_summary;
    hbar City / response=city_count  categoryorder=respdesc;
    xaxis label="City";
    yaxis label="Number of People Invited";
run;

Note that for many of the graph types sorting the data doesn't really translate to order in the graph unless there is a DATA option for an some sort of Order related option.

View solution in original post

2 REPLIES 2
ballardw
Super User

If you want the the plot to be sorted by the Response variable value you use the option CATEGORYORDER with either RESPASC or RESPDESC to order in response variable ascending or descending order respectively.

 

proc sgplot data=sorted_invites_summary;
    hbar City / response=city_count  categoryorder=respdesc;
    xaxis label="City";
    yaxis label="Number of People Invited";
run;

Note that for many of the graph types sorting the data doesn't really translate to order in the graph unless there is a DATA option for an some sort of Order related option.

davidjayjackson
Fluorite | Level 6
Thanks, that was what I was looking for.

David

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

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1280 views
  • 1 like
  • 2 in conversation