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.
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.
Thanks in advance!
Do you want the data or the graph directly? Both are pretty simple in SAS 🙂
Dear Buddy
I need as a data. I could convert it to diagram.
The above information is just a sample.
Ok. So the posted example data should not result in the posted desired result, correct?
@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;
Also, is your data representative of your example? How does the value 66.4 occur for instance?
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!
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.