Hello
I want to create a simple bar chart that show for each score ,sum of loans.
I want that in the top of each bar there will be a label with PCT_SUM_LOAN information.
What is the way to it please?
Data summaryinfo;
input Score $ sum_loans;
cards;
0 30
2-4 120
5-6 50
7-8 30
9-12 15
13 5
;
run;
Proc SQL;
Create Table summaryinfo2 AS
Select *,(sum_loans/SUM(sum_loans)) AS PCT_SUM_LOAN format=percent6.2
From summaryinfo
;
Quit;
title;
proc sgplot data=summaryinfo2 noborder;
vbarparm category=Score response=sum_loans/group=Score groupdisplay=cluster
datalabel dataskin=pressed;
xaxis display=(noticks noline nolabel);
yaxis display=(noticks nolabel noline) grid;
run;
Hi @Ronein
Maybe more basic in terms of appearance, but with the display of percentages:
NB: I encourage you to use a format for categories.
Data summaryinfo;
input Score sum_loans;
format Score score.;
cards;
0 30
1 120
2 50
3 30
4 15
5 5
;
run;
proc format;
value score
0 = "0"
1 = "2-4"
2 = "5-6"
3 = "7-8"
4 = "9-12"
5 = "13";
run;
title;
axis1 label=none;
proc gchart data=summaryinfo;
vbar score / freq=sum_loans percent type=freq discrete raxis=axis1;
run;
Using your code, I see the following. Isn't that what you want?
I want to show labels of PCT
12%
48%
20%
12%
6.0%
2.0%
and the bar height will be relatd to values:
30
120
50
30
15
5
Hi @Ronein
Maybe more basic in terms of appearance, but with the display of percentages:
NB: I encourage you to use a format for categories.
Data summaryinfo;
input Score sum_loans;
format Score score.;
cards;
0 30
1 120
2 50
3 30
4 15
5 5
;
run;
proc format;
value score
0 = "0"
1 = "2-4"
2 = "5-6"
3 = "7-8"
4 = "9-12"
5 = "13";
run;
title;
axis1 label=none;
proc gchart data=summaryinfo;
vbar score / freq=sum_loans percent type=freq discrete raxis=axis1;
run;
Thank you.
What will be the way to create labels above each bar with sum_loans information?
(So we will see the numbers 30,120,50,30,15,5) above the bars
Hi @Ronein
To put sum_loans values instead of percent above the bars, you can simply replace 'percent' by 'freq' in the below code:
title;
axis1 label=none;
proc gchart data=summaryinfo;
vbar score / freq=sum_loans freq type=freq discrete raxis=axis1;
run;
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.