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

If I want to calculate the mean of a subgroup (for example I want to calculate the mean cholesterol of White men and White women) and I have variables for cholesterol, race, and sex, how would I combine the variables I need in order to get the averages I am looking for?

1 ACCEPTED SOLUTION
4 REPLIES 4
sassypixie
Fluorite | Level 6

I actually tried a different way although I am not 100% sure if it's correct

Proc means data=data;
var cholesterol;
class sex;
where race= 2;
run;

Would this way be still sufficient? 

ballardw
Super User

Typically I would use Proc Summary to create a data set if that is the need.

 

Proc summary data=have;
   class sex race;
   var cholesterol;
   output out=work.summary mean=;
run;

The resulting data will have summary of 1) overall 2)each level of sex, 3)each level of race and 4) each combination of sex and race that appears in the data with the mean for each group. There is a variable _type_ that can be used to select which "group" you want for other processing. If you had other variables that you want to summarize, such as weight, blood pressure or what have you, add those variables to the VAR statement. If you want more statistics then add them such as min= max= std= /autoname. The Autoname option appends the statistics abbreviation to the variable name so you can tell the values apart. If only one statistic is used then the above syntax uses the existing name and it is up to you to know that it is a mean value.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1242 views
  • 4 likes
  • 3 in conversation