BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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;

Capture d’écran 2020-02-09 à 10.16.54.png

View solution in original post

5 REPLIES 5
Norman21
Lapis Lazuli | Level 10

Using your code, I see the following. Isn't that what you want?

 

Annotation 2020-02-09 082756.png

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

Ronein
Meteorite | Level 14

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

ed_sas_member
Meteorite | Level 14

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;

Capture d’écran 2020-02-09 à 10.16.54.png

Ronein
Meteorite | Level 14

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

 

ed_sas_member
Meteorite | Level 14

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 498 views
  • 2 likes
  • 3 in conversation