How do I compute the sample mean and variances for each individual observation? I want to used the variances to test for equality of variances.
data one;
input xx xxx@@;
datalines;
0 5.5 0 9.5 0 9.5 0 9.5 0 9.5 0 10.0
6 11.0 6 15.5 6 16.0 6 18.0 6 18.0 6 18.0
12 19.5 12 20.5 12 22.0 12 22.0 12 23.5 12 27.0
18 24.5 18 26.5 18 26.5 18 27.5 18 27.5 18 28.0
24 26.5 24 27.5 24 28.0 24 28.5 24 31.0 24 33.5
;
proc print;
run;
@JUMMY wrote:
How do I compute the sample mean and variances for each individual observation? I want to used the variances to test for equality of variances.
data one; input xx xxx@@; datalines; 0 5.5 0 9.5 0 9.5 0 9.5 0 9.5 0 10.0 6 11.0 6 15.5 6 16.0 6 18.0 6 18.0 6 18.0 12 19.5 12 20.5 12 22.0 12 22.0 12 23.5 12 27.0 18 24.5 18 26.5 18 26.5 18 27.5 18 27.5 18 28.0 24 26.5 24 27.5 24 28.0 24 28.5 24 31.0 24 33.5 ; proc print; run;
Can you please clarify. Are you looking for the mean of all records for each XX or for each row of data? Not sure how you could calculate the mean/variance for a single observation.
Otherwise, if you're doing it per row, and have a 'wide' format, you can use the MEAN() and VAR() function.
For each XX, just use PROC MEANS and put the grouping variable in the CLASS or BY statement.
Here's an example for PROC MEANS.
https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas
Since each of your observations (probably not what you meant, SAS specifically uses observation to reference a single record or row of data) in your resulting data set has exactly one value of XXX the mean for each would be the value of XXX and variance would be 0 because there is only on value per observation.
I am going to assume that you want the mean and variance of XXX for each value of XX.
That would be, assuming you want a data set:
proc summary data=one nway; class xx; var xxx; output out=want mean= var= / autoname; run;
Want would have two variables XXX_mean and XXX_var for the mean and variance for each value of xxx.
Though perhaps Proc Anova would be appropriate directly with data set one for input. Such as:
proc anova data=one; class xx; model xxx = xx; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.