Hi:
I -think- I understand what you mean when you say
mean for var or sum for var -- I think you're asking what if you want mean for AGE and SUM for HEIGHT?? If so, then try the following amendment to the first code I posted. You can control the specific name that's assigned and ONLY get a statistic for 1 variable instead of for all the variables in the VAR statement by coding a slightly different construction on the OUTPUT statement...generally:
stat(varname)=newvarname. So in the example below, I am getting the N for AGE, the SUM for HEIGHT, the MEAN for AGE and the MEDIAN value for both numbers with the default names for the remaining 2 variables.
Consider this code:
[pre]
proc means noprint data = sashelp.class n sum mean median;
var age height;
class sex;
output out=stats2 n(age)=agecnt
sum(height)=htsum
mean(age)=ageavg
median=;
run;
proc print data=stats2;
title '2) Control names selectively and only get some statistics';
title2 'N for AGE, only; SUM for HEIGHT only; MEAN for AGE, only; default names for MEDIAN';
run;
[/pre]
Produces this output:
[pre]
2) Control names selectively and only get some statistics
N for AGE, only; SUM for HEIGHT only; MEAN for AGE, only; default nam
Obs Sex _TYPE_ _FREQ_ agecnt htsum ageavg Age Height
1 0 19 19 1184.4 13.3158 13.0 62.80
2 F 1 9 9 545.3 13.2222 13.0 62.50
3 M 1 10 10 639.1 13.4000 13.5 64.15
[/pre]
There's another example in the doc here:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#/documentation/cdl/en...
Also you asked what the CLASS statement was doing...the CLASS statement is telling PROC MEANS that I want the statistics for all the rows in my DATA= file (_TYPE_ = 0) and that I want a separate row of statistics for SEX=F (_TYPE_=1) and a separate row of statistics for SEX=M (_TYPE_ = 1).
Using a CLASS statement allows me to set categories, in much the same way that the CLASS statement is used for PROC TABULATE -- it sets groups or categories -- so that the statistics can be calculated for the groups separate
from the statistics for the whole dataset. For example, you can see that the average age for the whole group of 19 observations is 13.3158, but that the 9 females have an average age of 13.2222; while the average age for the 10 males is 13.40 -- that particular feature may not be useful to you right now, but is handy to know about. (Without the CLASS statement, you would only get the _TYPE_=0 row in the output dataset.)
cynthia