Lapis Lazuli | Level 10

## Evaluate a percentage of value - for report as bardiagram(Excel)

Hi Community

Here I have a sample data set - the column which contain some values.

``````data have;
input val1 val2;
cards;
6.3 7.2
6.6 8.1
6.8 6
7 12
7.5 5
8 7.8
9.1 8
1.3 2
12.1 7
;
run;``````

I want to report the data as the below image.

Bar Diagram

Orange bar - Val1 , Blue bar - Val2

(Condition 1) <7

(Condition 2) 7 to 8

(Condition 3) >8

While calculate the Val1's in bar it should like - 8.9 + 24.7 + 66.4 = 100

While calculate the Val2's in bar it should like - 23.4 + 41.1 + 35.5 = 100

 Val1 Val2 <7 8.9 23.4 7 to 8 24.7 41.1 >8 66.4 35.5

Please suggest me to solve it.

5 REPLIES 5
Tourmaline | Level 20

## Re: Evaluate a percentage of value - for report as bardiagram(Excel)

Do you want the data or the graph directly? Both are pretty simple in SAS 🙂

Lapis Lazuli | Level 10

## Re: Evaluate a percentage of value - for report as bardiagram(Excel)

Dear Buddy

I need as a data. I could convert it to diagram.

The above information is just a sample.

Tourmaline | Level 20

## Re: Evaluate a percentage of value - for report as bardiagram(Excel)

Ok. So the posted example data should not result in the posted desired result, correct?

Super User

## Re: Evaluate a percentage of value - for report as bardiagram(Excel)

@Sathish_jammy wrote:

Dear Buddy

I need as a data. I could convert it to diagram.

The above information is just a sample.

Large economy sized hint for future posts: You show a "calculation" but the numbers posted should be possible to be made using your example data.

Since there is essentially no way to verify how you get 8.9 24.7 or 66.4 I am guessing that the following might work.

BTW it is very hard to use a single variable to both group data and generate a sum.

```data have;
input val1 val2;
length grp \$ 10;
grp='Baseline';value=val1; vgrp=val1;output;
drop val1 val2;
cards;
6.3  7.2
6.6  8.1
6.8  6
7    12
7.5  5
8    7.8
9.1  8
1.3  2
12.1 7
;
run;
proc format library=work;
value val
low -<7 = '<7'
7  -  8 = '7-8'
8 <- high='>8'
;

proc tabulate data=have out=want;
class grp vgrp;
format vgrp val.;
var value;
table vgrp='' *value='',
grp=' '*(sum colpctsum)
/ row=float
;
run;

```

I reshape the data adding explicit grouping variables for you baseline/followup and the value used to group. Then the format can be applied to one for grouping purposes of the value and other summed.

Proc Tabulate will do column percent which I think is what you intended.

And a basic plot:

```Proc sgplot data=want;
vbar  vgrp / response=value_PctSum_10_value group=grp
groupdisplay=cluster  datalabel= value_PctSum_10_value
;
label vgrp='Percent group';   label grp='Time frame';   keylegend /location=inside position=topleft;
yaxis display=(nolabel);
run;

```
Tourmaline | Level 20

## Re: Evaluate a percentage of value - for report as bardiagram(Excel)

Also, is your data representative of your example? How does the value 66.4 occur for instance?

Discussion stats
• 5 replies
• 721 views
• 0 likes
• 3 in conversation