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

 

 

I am creating a bar graph using the following sgplot, the bar graph generated is sorted by the aedecod alphabetically, but I really want to bar graph sorted by the frequency of the aedecod, 

 

proc sgplot data=SAE;
hbar aedecod / datalabel
fillattrs=graphdata2;
yaxis display=(nolabel);
xaxis grid;
run;

 

Thank you so much!!

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @zimcom,

 

Add the CATEGORYORDER= option to the existing options (DATALABEL and FILLATTRS=...) of the HBAR statement:

categoryorder=respdesc

to sort by descending frequencies or

categoryorder=respasc

to sort by ascending frequencies.

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hi @zimcom,

 

Add the CATEGORYORDER= option to the existing options (DATALABEL and FILLATTRS=...) of the HBAR statement:

categoryorder=respdesc

to sort by descending frequencies or

categoryorder=respasc

to sort by ascending frequencies.

zimcom
Pyrite | Level 9
Thank you so much!!!

Another wish to have, can i add the total count in the graph title?
FreelanceReinh
Jade | Level 19

@zimcom wrote:
Another wish to have, can i add the total count in the graph title?

Sure. I would probably use a preliminary (DATA or PROC SQL) step to determine the total count and assign it to a macro variable. A reference to this macro variable could then be used in the TITLE statement.

 

Example -- assuming that the number of observations in dataset SAE equals the total count you need:

data _null_;
call symputx('nSAE',n);
stop;
set sae nobs=n; 
run;

title "SAE frequencies (total=&nSAE)";

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 978 views
  • 0 likes
  • 2 in conversation