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

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS Training: Just a Click Away

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

Browse our catalog!

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