BookmarkSubscribeRSS Feed
Sathish_jammy
Lapis Lazuli | Level 10

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 DiagramBar 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

 Val1Val2
<78.923.4
7 to 824.741.1
>866.435.5

Please suggest me to solve it.

Thanks in advance!

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

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

Sathish_jammy
Lapis Lazuli | Level 10

Dear Buddy

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

The above information is just a sample.

 

 

 

PeterClemmensen
Tourmaline | Level 20

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

ballardw
Super User

@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;
   grp='Follow Up';value=val2; vgrp=val2;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;
PeterClemmensen
Tourmaline | Level 20

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 914 views
  • 0 likes
  • 3 in conversation