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

In this example there are 4 fields:

Month- period of the informaton

ACTUAL- Sum of Loans that were taken in Millions of $ 

OFFERED-Sum of offers of loans that were given to customers in Millions of $

PCT_USED - percet of offers that were used by loans

I want to create a visual way (chart) to show this summary table.

In the x-asix will be month

In Y-axis1 will be amount in Millions of $

In Y-axis2 will be PCT in %

What is the best way to create for each month 2 bars (one for ACTUAL and second for OFFERED) and also create a line chart of PCT_USED?

 

If there is another good way to represent the information then I will be happy to learn.

 

I also think of another way to show it:

For each month will have 1 stack bar (with information about ACTUAL and  OFFERED) and also create a line chart of PCT_USED?

 

Data example_Summary_Info;
Retain Month ACTUAL	OFFERED	PCT_USED;
informat PCT_USED percent9.1;
format  PCT_USED percent9.1;
Input Month $	ACTUAL	OFFERED	PCT_USED;
cards;
10/18 250 485 51.5%
11/18 432 860 50.2%
12/18 497 950 52.3%
01/19 483 898 53.8%
02/19 435 776 56.1%
03/19 436 784 55.6%
04/19 396 684 57.9%
05/19 486 831 58.5%
06/19 438 764 57.3%
07/19 461 821 56.2%
08/19 393 714 55.0%
09/19 377 668 56.4%
10/19 358 638 56.1%
11/19 411 713 57.6%
12/19 420 728 57.7%
;
Run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

This should get you started. Feel free to ask 🙂

 

Data example_Summary_Info;
Retain Month ACTUAL	OFFERED	PCT_USED;
informat PCT_USED percent9.1;
format  PCT_USED percent9.1;
Input Month $	ACTUAL	OFFERED	PCT_USED;
cards;
10/18 250 485 51.5%
11/18 432 860 50.2%
12/18 497 950 52.3%
01/19 483 898 53.8%
02/19 435 776 56.1%
03/19 436 784 55.6%
04/19 396 684 57.9%
05/19 486 831 58.5%
06/19 438 764 57.3%
07/19 461 821 56.2%
08/19 393 714 55.0%
09/19 377 668 56.4%
10/19 358 638 56.1%
11/19 411 713 57.6%
12/19 420 728 57.7%
;
Run;

data temp;
    set example_Summary_Info;
    p = OFFERED; group = "OFFERED"; output;
    p = actual;  group = "Actual";  output;
run;

proc sgplot data=temp;
    vbarparm category=Month response=p / group=group groupdisplay=cluster baselineattrs=(thickness=0) name='a';
    series x=Month y=PCT_USED / y2axis lineattrs=(color=gold thickness=4) name='b';
    xaxis display=(nolabel);
    keylegend / title="";
run;

View solution in original post

11 REPLIES 11
PeterClemmensen
Tourmaline | Level 20

This should get you started. Feel free to ask 🙂

 

Data example_Summary_Info;
Retain Month ACTUAL	OFFERED	PCT_USED;
informat PCT_USED percent9.1;
format  PCT_USED percent9.1;
Input Month $	ACTUAL	OFFERED	PCT_USED;
cards;
10/18 250 485 51.5%
11/18 432 860 50.2%
12/18 497 950 52.3%
01/19 483 898 53.8%
02/19 435 776 56.1%
03/19 436 784 55.6%
04/19 396 684 57.9%
05/19 486 831 58.5%
06/19 438 764 57.3%
07/19 461 821 56.2%
08/19 393 714 55.0%
09/19 377 668 56.4%
10/19 358 638 56.1%
11/19 411 713 57.6%
12/19 420 728 57.7%
;
Run;

data temp;
    set example_Summary_Info;
    p = OFFERED; group = "OFFERED"; output;
    p = actual;  group = "Actual";  output;
run;

proc sgplot data=temp;
    vbarparm category=Month response=p / group=group groupdisplay=cluster baselineattrs=(thickness=0) name='a';
    series x=Month y=PCT_USED / y2axis lineattrs=(color=gold thickness=4) name='b';
    xaxis display=(nolabel);
    keylegend / title="";
run;
Ronein
Meteorite | Level 14

This is the chart that I made but i need to improve it.

I need to add also information about ACTUAL field (one way is to add another bar for each month and second way is to create stack bar with information of ACTUAL and OFFERED fields)

 

proc sgplot data=example_Summary_Info noborder;
    vbar month / response=OFFERED dataskin=pressed baselineattrs=(thickness=0) fillattrs=graphdata1 
            name='a' nostatlabel;
    vline month / response=PCT_USED y2axis lineattrs=(color=gold thickness=4) nostatlabel name='b';
    xaxis discreteorder=data display=(noline nolabel noticks);
    yaxis display=(noline noticks) grid label='(Millions USD)' values=(200 to 1000 by 50) offsetmin=0;
    y2axis display=(noline noticks) values=(0 to 1 by 0.05) offsetmin=0;
    keylegend 'a' 'b' / title='' linelength=24;
run;
PeterClemmensen
Tourmaline | Level 20

Did you try my code?

Ronein
Meteorite | Level 14

It is great, Thank you.

What about display ACTUAL and OFFERED together in one bar (stack bar).

Do you think it is better ?

What is the way to do it?

 

PeterClemmensen
Tourmaline | Level 20

Simply do

 

proc sgplot data=temp;
    vbarparm category=Month response=p / group=group groupdisplay=stacked baselineattrs=(thickness=0) name='a';
    series x=Month y=PCT_USED / y2axis lineattrs=(color=gold thickness=4) name='b';
    xaxis display=(nolabel);
    keylegend / title="";
run;

Whether it is better or not, it depends on what you want to show. 

Ronein
Meteorite | Level 14

There are some small features that I want to make from your code please.

1-I want to change the label in Y-axis from "P" to "Amnt in millions $" 

2-Below the chart I want to change the label of the yellow line from "PCT_USED" to "%Use"

3-I want to add a title within the chart to "Loans/Offers by Month"

 

 

ed_sas_member
Meteorite | Level 14

Hi @Ronein 

 

Here is an attempt to achieve this:

 

proc sgplot;
	vbar month / response = ACTUAL legendlabel='Sum of Loans that were taken' ;
	vbar month / response = OFFERED barwidth=0.5 legendlabel='Sum of offers of loans that were given to customers';
	vline month / response = PCT_USED y2axis lineattrs=(color=gold thickness=3) legendlabel='% of offers that were used by loans';
	xaxis display=(noline noticks) label='(Month)' grid ;
	yaxis display=(noline noticks) label='(Millions of $)';
	y2axis display=(noline noticks) label='%' values=(0 to 1 by .05);
run;

Capture d’écran 2020-02-06 à 12.43.20.png

 

ed_sas_member
Meteorite | Level 14
proc sgplot;
	title "Loans/Offers by Month";
	vbar month / response = OFFERED legendlabel='Sum of offers of loans that were given to customers';
	vbar month / response = ACTUAL legendlabel='Sum of loans that were taken' ;
	vline month / response = PCT_USED y2axis lineattrs=(color=gold thickness=3) legendlabel='%Use';
	xaxis display=(noline noticks) label='Month' grid ;
	yaxis display=(noline noticks) label='Amnt in millions $';
	y2axis display=(noline noticks) label='%' values=(0 to 1 by .05);
run;
Ronein
Meteorite | Level 14

Thank you!

I see that  in your output there are 3 bar charts and not 2 ( and 2 of the 3 are same). why?  

ed_sas_member
Meteorite | Level 14

Hi @Ronein 

 

This is actually what I get -> so 2 bar charts (overlayed) and one line 

Capture d’écran 2020-02-06 à 12.52.20.png

Ronein
Meteorite | Level 14

Why are there 2 blue bar charts in same height??

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 11 replies
  • 808 views
  • 2 likes
  • 3 in conversation