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!!
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.
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 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)";
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.