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:
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:
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;
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.
Here is one possibility:
The key changes in the program below are the following:
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;
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;
thank you very match
Idit Maor
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!
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.