I am using psglot (vbar ) to display stacked bar. I need to display only one segment label and sum in second.
When i try using calculated var(sum) the range is getting increased.
Here is sample data.
date | X1 | Y1 | Sum |
jan | 2 | 3 | 5 |
feb | 5 | 1 | 6 |
mar | 6 | 4 | 10 |
apr | 3 | 4 | 7 |
data have;
input date$ X1 Y1 Sum;
cards;
jan 2 3 5
feb 5 1 6
mar 6 4 10
apr 3 4 7
;
data want;
set have;
array chars(*) x1 sum;
do i = 1 to dim(chars);
new=chars(i);
newc=vname(chars(i));
output;
end;
run;
proc sgplot data=want noborder;
vbar date / response=new group=newc seglabel
baselineattrs=(thickness=0)
outlineattrs=(color=cx3f3f3f);
xaxis display=(nolabel noline noticks);
yaxis display=(noline noticks) grid;
run;
Thanks.
This I am already getting. If you look into Y axis, the value has increased from 7 to 10 for apr data.
If you look into apr data. sum of x and y are 7. Y axis value should not increase.
IN the data step from @Jagadishkatam , I think this statement:
array chars(*) x1 sum;
should be:
array chars(*) x1 y1;
which will give the answer you expect.
Sorry, I misunderstood your request, so ignore my previous reply. To do what you want is a special case different from displaying the segment value using SEGLABEL. Your trying to show the cumulative values in the bar. To do this, you will need to do some data processing outside of SGPLOT. Here are the basic steps:
1. Transpose your data as described by @Jagadishkatam , but using the X1 and Y1 variables.
2. Pre-summarize your data using PROC SUMMARY or PROC MEANS.setting CLASS to be DATE and NEWC.
3. Using that data, calculate the middle value in each segment (we'll call that var "middle"). At the same time, accumulate the sums for each bar segment and put it in a variable called "seglabel".
4. Render using SGPLOT with something like this:
proc sgplot data=whatever;
vbarparm category=date response=sumvar / group=newc;
text x=date y=middle text=seglabel;
run;
Hope this helps!
Dan
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.