(View the complete code for this example.)
The following example illustrates the use of PROC SIMNORMAL to generate two normal random variates that have specified means and covariance.
In this example, the means and covariances are given; these might have come from previous experiments, observational studies, or other considerations.
First you create a _TYPE_=COV data set as the input data set, and then you run PROC SIMNORMAL with NUMREAL=5000, creating a sample that contains 5,000 observations. The simple statistics of this sample are checked using PROC CORR. The results are shown in Figure 1.
data scov(type=COV) ;
input _TYPE_ $ 1-4 _NAME_ $ 9-10 S1 S2 ;
datalines ;
COV S1 1.915 0.3873
COV S2 0.3873 4.321
MEAN 1.305 2.003
;
proc simnormal data=scov outsim=ssim
numreal = 5000
seed = 54321 ;
var s1 s2 ;
run;
proc corr data=ssim cov ;
var s1 s2 ;
title "Statistics for PROC SIMNORMAL Sample Using NUMREAL=5000" ;
run;
Figure 1: Statistics for PROC SIMNORMAL Sample Using NUMREAL=5000
| Statistics for PROC SIMNORMAL Sample Using NUMREAL=5000 |
| 2 Variables: | S1 S2 |
|---|
| Covariance Matrix, DF = 4999 | ||
|---|---|---|
| S1 | S2 | |
| S1 | 1.895805499 | 0.424837163 |
| S2 | 0.424837163 | 4.132974275 |
| Simple Statistics | ||||||
|---|---|---|---|---|---|---|
| Variable | N | Mean | Std Dev | Sum | Minimum | Maximum |
| S1 | 5000 | 1.30254 | 1.37688 | 6513 | -3.90682 | 6.49864 |
| S2 | 5000 | 1.98790 | 2.03297 | 9940 | -5.69812 | 9.42833 |