BookmarkSubscribeRSS Feed
JUMMY
Obsidian | Level 7

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;

 

 

2 REPLIES 2
Reeza
Super User

@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

 

ballardw
Super User

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 9240 views
  • 0 likes
  • 3 in conversation