BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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

Ronein_0-1728024589299.png

 

 

3 REPLIES 3
yabwon
Onyx | Level 15

Example data?

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

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;

yabwon_0-1728029012641.png

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ksharp
Super User
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;

Ksharp_0-1728118400316.png

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 288 views
  • 1 like
  • 3 in conversation