BookmarkSubscribeRSS Feed
Ishaan
Calcite | Level 5

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. 

dateX1Y1Sum
jan235
feb516
mar6410
apr347

 

 

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
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;

 

image.png

Thanks,
Jag
Ishaan
Calcite | Level 5

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.

 

DanH_sas
SAS Super FREQ

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. 

DanH_sas
SAS Super FREQ

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

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