I have the data in following format:
Age | Age_group | Gender | Weight_group | Height_group |
11 | 1 | Male | 1 | 2 |
12 | 1 | Male | 1 | 3 |
12 | 1 | Male | 1 | 2 |
21 | 2 | Male | 1 | 3 |
14 | 1 | NA | 2 | 1 |
13 | 1 | Female | 2 | 2 |
23 | 2 | Female | 2 | 2 |
21 | 2 | Female | 3 | 1 |
24 | 2 | Female | 3 | 4 |
23 | 2 | Female | 3 | 4 |
13 | 1 | NA | 3 | 3 |
I need help to create the following table.
Characteristic |
| Height group | |||
|
| Group 1 | Group 2 | Group 3 | Group 4 |
Age | (mean) | --- (SD) | --- (SD) | --- (SD) | --- (SD) |
Age | Group 1 | ---(%) | ---(%) | ---(%) | ---(%) |
| Group 2 | ---(%) | ---(%) | ---(%) | ---(%) |
Gender | Male | ---(%) | ---(%) | ---(%) | ---(%) |
| Female | ---(%) | ---(%) | ---(%) | ---(%) |
| NA | ---(%) | ---(%) | ---(%) | ---(%) |
Weight | Group 1 | ---(%) | ---(%) | ---(%) | ---(%) |
| Group 2 | ---(%) | ---(%) | ---(%) | ---(%) |
| Group 3 | ---(%) | ---(%) | ---(%) | ---(%) |
Thanks in advance.
What does "--- (SD)" mean? "--- (%)"
Percentages imply a division with a numerator and denominator, so what would the numerator and denominators be?
By table do you mean a data set (used for further processing -if so this is going to be extremely difficult to work with) or a report that people read?
Please post the data you have in usable form and the output including the numbers you expect to see.
data have;
input Age Age_group $ Gender $ Weight_group $ Height_group $;
datalines;
11 1 Male 1 2
12 1 Male 1 3
12 1 Male 1 2
21 2 Male 1 3
14 1 NA 1 2
13 1 Female 2 2
23 2 Female 2 2
21 2 Female 3 1
24 2 Female 3 4
23 2 Female 3 4
13 1 NA 3 1
;
run;
I am trying to get a table in following format:
Characteristic |
| Height group | |||
|
| Group 1 | Group 2 | Group 3 | Group 4 |
Age | Mean (standard deviation) | 17.00 (5.66) | 14.60 (4.83) | 16.50 (6.36) | 23.50 (0.71) |
Age | Group 1 | 1 (50%) | 4 (80%) | 1 (50%) | 0 (0%) |
| Group 2 | 1 (50%) | 1 (20%) | 1 (50%) | 1 (100%) |
Gender | Male | 1(50%) | 2(40%) | 0 (0%) | 2 (100%) |
| Female | 0 (0%) | 2(40%) | 2 (100%) | 0 (0%) |
| NA | 1(50%) | 1(20%) | 0 (0%) | 0 (0%) |
Weight | Group 1 | 0 (0%) | 3 (60%) | 2(100%) | 0 (0%) |
| Group 2 | 0 (0%) | 2 (40%) | 0 (0%) | 0 (0%) |
| Group 3 | 2 (100%) | 0 (0%) | 0 (0%) | 2(100%) |
I can do this using two separate procedures:
proc means data=have maxdec=2;
var age;
class height_group;
run;
proc freq data = have;
table (age_group gender weight_group) * height_group;
run;
I am looking for a way to do this in a single step.
@MEL20 wrote:
data have;
input Age Age_group $ Gender $ Weight_group $ Height_group $;
datalines;
11 1 Male 1 2
12 1 Male 1 3
12 1 Male 1 2
21 2 Male 1 3
14 1 NA 1 2
13 1 Female 2 2
23 2 Female 2 2
21 2 Female 3 1
24 2 Female 3 4
23 2 Female 3 4
13 1 NA 3 1
;
run;
I am trying to get a table in following format:
Characteristic
Height group
Group 1
Group 2
Group 3
Group 4
Age
Mean
(standard deviation)
17.00
(5.66)
14.60
(4.83)
16.50
(6.36)
23.50 (0.71)
Age
Group 1
1 (50%)
4 (80%)
1 (50%)
0 (0%)
Group 2
1 (50%)
1 (20%)
1 (50%)
1 (100%)
Gender
Male
1(50%)
2(40%)
0 (0%)
2 (100%)
Female
0 (0%)
2(40%)
2 (100%)
0 (0%)
NA
1(50%)
1(20%)
0 (0%)
0 (0%)
Weight
Group 1
0 (0%)
3 (60%)
2(100%)
0 (0%)
Group 2
0 (0%)
2 (40%)
0 (0%)
0 (0%)
Group 3
2 (100%)
0 (0%)
0 (0%)
2(100%)
I can do this using two separate procedures:
proc means data=have maxdec=2;
var age;
class height_group;
run;proc freq data = have;
table (age_group gender weight_group) * height_group;
run;
I am looking for a way to do this in a single step.
None of the SAS statistical or report procedures will place two statistics into a single cell. I can get values as shown but not the layout with something like this as a "single step".
proc tabulate data=have;
class age_group gender weight_group height_group;
var age;
table age *(mean std)
(age_group
gender
weight_group)*(n colpctn)
, height_group
/misstext='0'
;
run;
Up to you to provide labels and maybe a custom format to show "Group x" instead of the value provided.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.