BookmarkSubscribeRSS Feed
MEL20
Calcite | Level 5

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.

5 REPLIES 5
ballardw
Super User

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?

andreas_lds
Jade | Level 19

Please post the data you have in usable form and the output including the numbers you expect to see.

MEL20
Calcite | Level 5

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.

 

 

 

ballardw
Super User

@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.

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
  • 1239 views
  • 0 likes
  • 4 in conversation