BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
IditMaor
Calcite | Level 5

hi,

this is my code:

data a;
infile cards expandtabs;
input year customer $ amount div;
cards;
1994 AAA 1000 500
1994 A 800 .
1994 BBB 500 .
1994 c 10 .
1995 AAA 2000 1500
1995 A 1500 .
1995 BBB 500 .
1995 c 100 .
1996 AAA 800 600
1996 A 1200 .
1996 BBB 200 .

;

proc sgplot data=a;
vbar year / response=amount group=customer groupdisplay=cluster
grouporder=data nostatlabel datalabel ;
yaxis grid display=(nolabel);
xaxis display=(nolabel);
run;

this is the output:

IditMaor_0-1657460360284.png

1. I need the numbers to be on the bars and not on top of the bars.

2. I need to add the variable "div" on the bars, how to do this?

then graphs needs to look like this:

IditMaor_1-1657460510824.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data a;
infile cards expandtabs;
input year customer $ amount div;
x1=10;
x2=400;
format div percent10.0;
cards;
1994 AAA 1000 .5
1994 A 800 .5
1994 BBB 500 .5
1994 c 10 .5
1995 AAA 2000 .15
1995 A 1500 .15
1995 BBB 500 .15
1995 c 100 .15
1996 AAA 800 .6
1996 A 1200 .6
1996 BBB 200 .6

;

proc sgplot data=a noborder  noautolegend ;
styleattrs datacolors=(CX238B45 CX74C476 CXBAE4B3 CXEDF8E9);

vbarparm category=year  response=amount /group=customer  groupdisplay=cluster grouporder=data 
nooutline barwidth=0.9 ;


text x=year y=x1 text=amount/position=right group=customer groupdisplay=cluster  
rotate=90 strip contributeoffsets=none textattrs=(size=10 weight=bold color=black);

text x=year y=x2 text=div/backfill fillattrs=(color=orange) 
textattrs=(size=10  weight=bold color=black)  strip contributeoffsets=none;

yaxis grid display=(nolabel noline noticks);
xaxis display=(nolabel);
run;

Ksharp_0-1657627172143.png

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Will the SEGLABEL do what you want instead of DATALABEL?

data a;
infile cards expandtabs;
input year customer $ amount div;
cards;
1994 AAA 1000 500
1994 A 800 .
1994 BBB 500 .
1994 c 10 .
1995 AAA 2000 1500
1995 A 1500 .
1995 BBB 500 .
1995 c 100 .
1996 AAA 800 600
1996 A 1200 .
1996 BBB 200 .

;

proc sgplot data=a;
   vbar year / response=amount group=customer groupdisplay=cluster
               grouporder=data nostatlabel 
               seglabel 
   ;
   yaxis grid display=(nolabel);
   xaxis display=(nolabel);
run;

DATALABEL is for the entire bar. SEGLABEL is for the segments created by the Group variable.

 

What/where is the DIV value supposed to appear? If you want much control you may have to move to combining a VBARBASIC and maybe a Text plot. VBAR graphs are restricted as to which other plots they combine with.

DanH_sas
SAS Super FREQ

Here is one possibility:

Screen Shot 2022-07-11 at 9.17.52 PM.png

The key changes in the program below are the following:

  1. RETAIN a column in the data step to position the DIV labels against the Y axis
  2. Replace all of the missing values in the DIV column with the correct DIV value for that observation
  3. Use a VBARPARM instead of a VBAR so that you can overlay the TEXT plot
  4. Use a SEGLABEL instead of a DATALABEL to move the bar values inside of the bars
  5. Use a TEXT plot to render the DIV labels on top of the bar chart

Let me know if you have any questions about this approach.

 

Thanks!

Dan

data a;
infile cards expandtabs;
retain ydiv 100;
input year customer $ amount div;
cards;
1994 AAA 1000 500
1994 A 800 500
1994 BBB 500 500
1994 c 10 500
1995 AAA 2000 1500
1995 A 1500 1500
1995 BBB 500 1500
1995 c 100 1500
1996 AAA 800 600
1996 A 1200 600
1996 BBB 200 600
;

proc sgplot data=a;
vbarparm category=year response=amount / group=customer groupdisplay=cluster
         grouporder=data seglabel seglabelattrs=(color=white);
text x=year y=ydiv text=div / textattrs=(size=12pt)
     backfill fillattrs=(color=tan) strip;
yaxis grid display=(nolabel);
xaxis display=(nolabel);
run;
Ksharp
Super User
data a;
infile cards expandtabs;
input year customer $ amount div;
x1=10;
x2=400;
format div percent10.0;
cards;
1994 AAA 1000 .5
1994 A 800 .5
1994 BBB 500 .5
1994 c 10 .5
1995 AAA 2000 .15
1995 A 1500 .15
1995 BBB 500 .15
1995 c 100 .15
1996 AAA 800 .6
1996 A 1200 .6
1996 BBB 200 .6

;

proc sgplot data=a noborder  noautolegend ;
styleattrs datacolors=(CX238B45 CX74C476 CXBAE4B3 CXEDF8E9);

vbarparm category=year  response=amount /group=customer  groupdisplay=cluster grouporder=data 
nooutline barwidth=0.9 ;


text x=year y=x1 text=amount/position=right group=customer groupdisplay=cluster  
rotate=90 strip contributeoffsets=none textattrs=(size=10 weight=bold color=black);

text x=year y=x2 text=div/backfill fillattrs=(color=orange) 
textattrs=(size=10  weight=bold color=black)  strip contributeoffsets=none;

yaxis grid display=(nolabel noline noticks);
xaxis display=(nolabel);
run;

Ksharp_0-1657627172143.png

 

IditMaor
Calcite | Level 5

thank you very match

Idit Maor

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 996 views
  • 3 likes
  • 4 in conversation