Hello
Let's say that I have a data of people who ride bicycle.
I want to learn from the data -
freq(proprtion)of perople who ride Long distance in each weekday
freq(proprtion)of perople who ride short distance in each weekday
(So there are 2 categoris-long/short dsistance)
What is the way to create such bar chart in order to display it
Example data?
How about something like this for start:
proc sort data=sashelp.heart out=temp;
by bp_status status;
run;
proc freq data=temp noprint order=data;
by bp_status;
table status/out=temp2 outcum;
run;
proc sort data=temp2;
by bp_status status;
run;
data annotation;
set temp2;
by bp_status;
lag_percent=LAG(cum_pct);
function="text";
drawspace="datavalue";
justify="center";
textsize=10;
width=100;
widthunit="percent";
YC1=bp_status;
if first.bp_status then lag_percent=0;
label=strip(put(count,9.-L)) !! "(" !! strip(put(percent,8.2) !! '%)');
anchor="left";
x1=lag_percent+1;
output;
run;
proc sgplot data=temp2 sganno=annotation ;
hbar bp_status /
group=status
response=percent
grouporder=data
;
run;
Bart
proc freq data=sashelp.heart noprint;
table bp_status*sex/out=out outpct list;
run;
data out2;
set out;
by bp_status;
label=cats(count,'/(',put(PCT_ROW,8.1),'%)');
if first.bp_Status then cum_p=0;
pos=cum_p+PCT_ROW/2;
cum_p+PCT_ROW;
run;
proc sgplot data=out2;
hbarparm category=bp_status response=PCT_ROW/group=sex;
text x=pos y=bp_status text=label/strip contributeoffsets=none
splitchar='/' splitpolicy=splitalways textattrs=(size=12 color=white);
xaxis label='Proportion(%)';
yaxis label='Weekday';
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.