BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Akter
Obsidian | Level 7

Hello,

Could you pls suggest me how can i get Overall mean and mean for scores by Gender using PROC SUMMARY. See the  dataset and the output tables i want; I'm struggling to get the Overall Mean for Score1 and Score 2 according to Gender (Male, Female). 

data Made;

ID Gender Score1 Score2
101 M 10 8
102 F 9 12
103 M 7 5
104 F 5 8

 

output want;

Gender  All
(mean)
Score1
(mean)
Score2
(mean)
M      
F      
Total (mean)      

 

Thank you,

Akter

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

 

Here you are:

data have;
input ID $ Gender $ Score1 Score2;
cards;
101	M	10	8
102	F	9	12
103	M	7	5
104	F	5	8
;
run;

PROC SUMMARY data=have;
 CLASS Gender;
 var Score: ;
 output out=summary_want;
run;

PROC PRINT data=summary_want;
 where _STAT_='MEAN';
run;
/* end of program */

Have a nice Sunday evening!

Koen

View solution in original post

6 REPLIES 6
sbxkoenk
SAS Super FREQ

Hello,

 

Here you are:

data have;
input ID $ Gender $ Score1 Score2;
cards;
101	M	10	8
102	F	9	12
103	M	7	5
104	F	5	8
;
run;

PROC SUMMARY data=have;
 CLASS Gender;
 var Score: ;
 output out=summary_want;
run;

PROC PRINT data=summary_want;
 where _STAT_='MEAN';
run;
/* end of program */

Have a nice Sunday evening!

Koen

sbxkoenk
SAS Super FREQ

Hello again,

 

(See also previous reply!)

 

Or do you want this? (It's not very clear from your question).

data have;
input ID $ Gender $ Score1 Score2;
cards;
101	M	10	8
102	F	9	12
103	M	7	5
104	F	5	8
;
run;

PROC SUMMARY data=have;
 CLASS Gender;
 var Score: ;
 output out=summary_want(where=(_STAT_='MEAN') drop=_TYPE_ _FREQ_);
run;

data summary_want;
 set summary_want;
 MeanScore1Score2 = mean(Score1,Score2);
run;
/* end of program */

Koen

sbxkoenk
SAS Super FREQ

Hello,

 

On top of the previous 2 replies I have given,

see here:

 

SAS Tip: Many Means to a Mean
Posted 02-12-2018 02:07 PM
https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Many-Means-to-a-Mean/m-p/436417#M...

 

Koen

Tom
Super User Tom
Super User

What is it you want in that first output column you have labeled ALL?

Tom
Super User Tom
Super User

I cannot figure out what statistic you want in that first column. Here is want the raw output of PROC MEANS/SUMMARY can easily produce.

proc summary data=have ;
  class gender;
  var score1 score2;
  output out=want mean= ;
run;

Results:

Obs    Gender    _TYPE_    _FREQ_    Score1    Score2

 1                  0         4       7.75       8.25
 2       F          1         2       7.00      10.00
 3       M          1         2       8.50       6.50
Akter
Obsidian | Level 7

Thank you. You all are so nice!

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
  • 6 replies
  • 2026 views
  • 4 likes
  • 3 in conversation