Contents: | Purpose / Requirements / Usage / Limitations |
%inc "<location of your file containing the MVN macro>";
Following this statement, you may call the %MVN macro. See the Results tab for an example.
The following parameters are required except for SEED=:
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Three methods are presented in increasing order of efficiency. In each case, the desired means (MU1 and MU2), variances (VAR1 and VAR2), and correlation coefficient (RHO) are specified. PROC CORR verifies that the generated data have the desired distribution.
data a;
keep x y;
mu1=10; mu2=20; var1=4; var2=9; rho=.5;
do i = 1 to 10000;
x = mu1+sqrt(var1)*rannor(123);
y = (mu2+rho*(sqrt(var2)/sqrt(var1))*(x-mu1)) +
sqrt(var2*(1-rho**2))*rannor(123);
output;
end;
run;
proc corr noprob; run;
data b;
keep x y;
mu1=10; mu2=20; var1=4; var2=9; rho=.5;
do i = 1 to 10000;
/* generate standard normal variates with corr of rho */
x = rannor(123);
y = rho*x+sqrt(1-rho**2)*rannor(123);
/* transform to designated mean and variance */
x = mu1 + sqrt(var1)*x;
y = mu2 + sqrt(var2)*y;
output;
end;
run;
proc corr noprob; run;
data c;
keep x y;
mu1=10; mu2=20; var1=4; var2=9; rho=.5;
std1=sqrt(var1); std2=sqrt(var2);
c=sqrt(1-rho**2);
do i = 1 to 10000;
x = rannor(123);
y = rho*x+c*rannor(123);
x = mu1 + sqrt(var1)*x;
y = mu2 + sqrt(var2)*y;
output;
end;
run;
proc corr noprob; run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Store the variance-covariance matrix in a data set */ data varcov; input m1-m3; cards; 4 1.8 4 1.8 9 3.6 4 3.6 16 ; /* Store the mean vector in a data set */ data means; input m1; cards; 10 20 30 ; /* Define the MVN macro */ %inc "<location of your file containing the MVN macro>"; %mvn(varcov=varcov, means=means, n=20000, sample=test) proc corr data=test noprob cov; run;
The CORR Procedure 3 Variables: COL1 COL2 COL3 Covariance Matrix, DF = 19999 COL1 COL2 COL3 COL1 3.95131676 1.77413626 4.00060059 COL2 1.77413626 9.02756640 3.58973133 COL3 4.00060059 3.58973133 16.18132889 Simple Statistics Variable N Mean Std Dev Sum Minimum Maximum COL1 20000 10.00995 1.98779 200199 2.60355 18.61083 COL2 20000 19.99845 3.00459 399969 8.57479 33.31395 COL3 20000 29.99947 4.02260 599989 15.04103 46.88934
Right-click on the link below and select Save to save
the %MVN macro definition
to a file. It is recommended that you name the file
mvn.sas
.
Type: | Sample |
Topic: | Analytics ==> Simulation Analytics ==> Transformations Analytics ==> Regression Analytics ==> Time Series Analysis Analytics ==> Matrix Programming Analytics ==> Mathematical Optimization Analytics ==> Exploratory Data Analysis Analytics ==> Financial Analysis Analytics ==> Forecasting SAS Reference ==> Procedures ==> CORR SAS Reference ==> Procedures ==> IML Analytics ==> Nonparametric Analysis Analytics ==> Descriptive Statistics |
Date Modified: | 2016-06-01 15:36:02 |
Date Created: | 2005-01-13 15:03:27 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/STAT | All | n/a | n/a |
SAS System | SAS/IML | All | n/a | n/a |