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