BookmarkSubscribeRSS Feed
CathyVI
Pyrite | Level 9

Hello,

I created 3 variables x1,x2,x3 with variance =9 from a simulate of 1000 copies. Now I want to:

1. Confirm that the empirical variances of (x1+x2) is consistent with Var x1 +x2 =Var (x1) +Var (x2) + 2Cov (x1, x2)

2. Confirm that the empirical covariance of (x1+x2) and (x1 + x3) is consistent with Cov (x1 +x2, x1 +x3 ) = Cov (x1, x1) +Cov (x1, x3) +Cov (x2, x1) +Cov (x2,x3).

It seems I can use PROC GLIMMIX but am not sure how to use the procedure.

How do I achieve this in sas. Thanks

2 REPLIES 2
PaigeMiller
Diamond | Level 26

PROC CORR will compute variances and covariances

 

proc corr data=have cov outp=covariance_matrix;
    var x1 x2 x3;
run;

 

The output data set contains covariances off the diagonal and variances on the diagonal in the rows where _TYPE_='COV'

--
Paige Miller
Rick_SAS
SAS Super FREQ

I don't think you need to use PROC GLIMMIX. You can form the variables x1+x2, x1+x3, and x2+x3 by using the DATA step and then generate the covariance matrix for those new variables. You can then read off the variances from the diagonal cells and the covariances from the off-diagonal cells and verify the identities. 

 

Since this sounds like a homework assignment, I will only provide a part of the solution. Use the following calls to generate the variance/covariance matrices. Can you use the output to verify the identities?

 

data Have;
set sashelp.iris(where=(Species="Versicolor"));
x1 = PetalLength;
x2 = PetalWidth;
x3 = SepalLength;
run;

proc corr data=Have COV outp=COV;
var x1 x2 x3;
ods select Cov;
run;

data Want;
set Have;
x1x2 = x1 + x2;
x1x3 = x1 + x3;
x2x3 = x2 + x3;
run;

proc corr data=Want COV outp=COVSum;
var x1x2 x1x3 x2x3;
ods select Cov;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 521 views
  • 3 likes
  • 3 in conversation