SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Abdulla1
Quartz | Level 8

Hello all

I've created the bar chart below, and I wonder if it is possible to let the bar chart show be both the frequency and the percentage ?

code"

PROC SGPLOT DATA = sashelp.cars;
VBAR type /group=origin;
RUN;

"

function output:

Abdulla1_0-1668697507530.png

wanted output examples

Abdulla1_2-1668697914184.png

thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
PROC SGPLOT DATA = sashelp.cars nocycleattrs;
VBAR type /group=origin;
VBAR type /group=origin y2axis stat=percent ;
RUN;

Ksharp_0-1668772344732.png

 

View solution in original post

5 REPLIES 5
Reeza
Super User
What is the denominator for the percentage? Overall or Per type?
Abdulla1
Quartz | Level 8

if it is possible to do it per type that would be great. 😄

 

Abdulla1
Quartz | Level 8

i think in order for it to work with the percentage per type we need to write the value inside each colored portion cause otherwise the percent access  needs a different bar as the percentage scale changes along the type
I found a way of adding the percent (out of total) in color like this but this losses the information of what each section of the bar represent (origin data in my example).

I wish I can keep write the percentage (and adjust it to pertype) value in the boxes instead of the frequency.

code :

PROC SGPLOT DATA = sashelp.cars;
VBAR type /group=origin COLORSTAT=PCT SEGLABEL;
RUN;

Abdulla1_1-1668709643778.png

 

 

Ksharp
Super User
PROC SGPLOT DATA = sashelp.cars nocycleattrs;
VBAR type /group=origin;
VBAR type /group=origin y2axis stat=percent ;
RUN;

Ksharp_0-1668772344732.png

 

Abdulla1
Quartz | Level 8

y2axis

that is just a great option.

thank you .

 

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!

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
  • 5 replies
  • 1529 views
  • 2 likes
  • 3 in conversation