Calcite | Level 5

simulatiom data with sas/iml

dear dr.rick

firstly thank you so much to invite me to this discussion, i need your help to correct this simulation commands .

i want to simulate 9 continuous variables (normal distribution ) and put it in linear model like multivariate regression model and this is the model .

%let N=1000;

proc iml;

/* specify the mean and covariance of the population */

Mean = {1, 2, 3, 2, 1, 4, 5, 6, 1};

Cov = {0.02 1.012 0.15 0.352 0.783 -0.023 0.298 0.402 0.759,

1.012 1.882 0.226 -0.301 0.974 0.112 -0.163 0.321 0.328,

0.15 0.226 1.025 2.289 -0.685 0.461 1.406 -0.106 -0.784,

0.352 -0.301 2.289 0.87 0.109 0.736 -1.16 -0.877 -0.411,

0.783  0.974 -0.685 0.109 -0.778 1.168 1.515 0.965 -1.08,

-0.023 0.112 0.461 0.736 1.168 -0.365 -0.219 -0.519 -0.054,

0.298 -0.163 1.406 -1.16 1.515 -0.219 -1.05 -0.849 1.556,

0.402  0.321 -0.106 -0.877 0.965 -0.519 -0.849 2.066 -0.198,

0.759  0.328 -0.784 -0.411 -1.08 -0.054 1.556 -0.198 -0.25};

call randseed(4321);

X = RandNormal(&N, Mean, Cov);               /* 1000 x 9 matrix     */

/* check the sample mean and sample covariance */

SampleMean = mean(X);                        /* mean of each column */

SampleCov =  cov(X);                         /* sample covariance   */

/* generate Y according to regression model */

beta = {2, 1, -1, 2, 1, 5, 6, 2, -2};               /* params, not including intercept */

Y = 1 + X*beta + eps;

/* write SAS data set */

varNames = ('x1':'x9') || {"Y"};

output = X || Y;

run;

regards

12 REPLIES 12
SAS Super FREQ

Re: simulatiom data with sas/iml

This is a public forum in which I am a participant. When I know an answer and have time to post it, I contribute to this forum. But I don't give personal assistance.

That said, your matrix is not a valid covariance matrix, Notice that your matrix has negative values along the diagonal.  These elements represents the variance estimates of each variable, and variance is never negative.

I discuss covariance matrices in Chap 10 of my book, Simulating Data with SAS.

Calcite | Level 5

Re: simulatiom data with sas/iml

dear dr.

i simulated this matrix by using ch10 in u book but i changed the type of the distribution from uniform here to normal and get on the previous covariance matrix . why i must use uniform dist. to simulate covariance matrix??

i am sorry i believed you are responsible on this forum.

regards

Calcite | Level 5

Re: simulatiom data with sas/iml

Hi All

anyone can help me to correct this commands to simulate multivariate regression analysis with 9 normal variables .

Best Regards

&let N=1000;

proc iml;

/* specify the mean and covariance of the population */

Mean = {1, 2, 3 , 4, 5, 6, 7, 8, 9};

cov = {0.8838659 0.9738211 0.5075826 0.8869405 0.6893635 0.9432546 0.9287864 0.487664 0.7798851,

0.9738211 0.8771385 0.5668343 0.6656078 0.8234433 0.9280248 0.7900982 0.1142881 0.8905852,

0.5075826 0.5668343 0.5448972 0.2810451 0.9316785 0.6140648 0.8564316 0.6149666 0.4655727,

0.8869405 0.6656078 0.2810451 0.5900954 0.7749225 0.4426628 0.0762391 0.9093871 0.5513743,

0.6893635 0.8234433 0.9316785 0.7749225 0.6663087 0.236998 0.1419535 0.3321644 0.3306588,

0.9432546 0.9280248 0.6140648 0.4426628 0.236998 0.7543832 0.6882105 0.6199138 0.7862424,

0.9287864 0.7900982 0.8564316 0.0762391 0.1419535 0.6882105 0.9863298 0.1584623 0.3849384,

0.487664 0.1142881 0.6149666 0.9093871 0.3321644 0.6199138 0.1584623 0.3205565 0.0744708,

0.7798851 0.8905852 0.4655727 0.5513743 0.3306588 0.7862424 0.3849384 0.0744708 0.4806334}

call randseed(4321);

X = RandNormal(&N, Mean, Cov);               /* 1000 x 9 matrix     */

/* check the sample mean and sample covariance */

SampleMean = mean(X);                        /* mean of each column */

SampleCov =  cov(X);                         /* sample covariance   */

/* print results */

c = "x1":"x9";

print (X[1000:9,]);

print SampleMean[colname=c];

print SampleCov[colname=c rowname=c];

/* write SAS/IML matrix to SAS data set for plotting */

create MVN from X[colname=c];  append from X;  close MVN;

quit;

run;

SAS Super FREQ

Re: simulatiom data with sas/iml

Same answer: your matrix is not positive definite, so it is not a valid covariance matrix. You can use the ROOT function to test for positive definiteness:

r = root(cov);

If you get the message "ERROR: Matrix should be positive definite" then the matrix is not a covariance matrix.  Again, see Chapter 10.

Calcite | Level 5

Re: simulatiom data with sas/iml

thank you so much dr. rick

i have some questions

1- how can i simulate covariance matrix (symmetric & positive definite ) because i simulate cov. matrix  via commands in ch 10 and i see this matrix not positive definite matrix.

2- when i doing simulation for multivariate regression models how can i put covariance matrix (optinal or by usin simulation like ch 10 in your book ).

best regards

Calcite | Level 5

Re: simulatiom data with sas/iml

dear dr. rick

this is simulation multivariate regression after checking covariance matrix  and i see now this phrase :

ERROR: (execution) Matrix has not been set to a value.

after regression equation

%let N=1000;

proc iml;

/* specify the mean and covariance of the population */

Mean = {1, 2, 3};

Cov = {3 2 1,

2 4 0,

1 0 5};

call randseed(4321);

X = RandNormal(&N, Mean, Cov);               /* 1000 x 3 matrix     */

/* check the sample mean and sample covariance */

SampleMean = mean(X);                        /* mean of each column */

SampleCov =  cov(X);                         /* sample covariance   */

/* generate Y according to regression model */

beta = {2, 1, -1};               /* params, not including intercept */

Y = 1 + X*beta + eps;

/* write SAS data set */

varNames = ('x1':'x3') || {"Y"};

output = X || Y;

run;

regards

Calcite | Level 5

Re: simulatiom data with sas/iml

Has eps been set to a value?

It might be helpful to look at the output in the log file directly following the line starting with ERROR.

Calcite | Level 5

Re: simulatiom data with sas/iml

thank you so much TomTom i wrote this value eps and now all variables without any value (missing values) .

regards

Calcite | Level 5

Re: simulatiom data with sas/iml

hi  all

i need your help to correct this model .

%let N=1000;

proc iml;

/* specify the mean and covariance of the population */

Mean = {1, 2, 3};

Cov = {3 2 1,

2 4 0,

1 0 5};

call randseed(4321);

X = RandNormal(&N, Mean, Cov);               /* 1000 x 3 matrix     */

eps = j(N, 3);                           /* allocate N x 3 vector   */

call randgen(eps, "Normal", 0, 1);   /* fill with random normal */

beta = {2, 1, -1};                      /* params, not including intercept */

eta = X*beta;                            /* linear predictor        */

Y = eta + eps;                            /* three simulated response  */

/* write SAS data set */

varNames = ('x1':'x3') || {"Y"};

output = X || Y;

create SimReg var {Y X1 X2 X3};  append;  close SimReg; /* write data */

run;

error occure in sas/ log

25         eps = j(N, 3);

ERROR: (execution) Matrix has not been set to a value.

and output :

there are a values in y only and x1-x3 missing values

 9.06396 . . . 8.76047 . . . -5.0354 . . . 5.06815 . . . -1.43449 . . . 4.28887 . . . 0.343735 . . . 0.190322 . . . 7.74863 . . . 9.13058 . . . 8.78907 . . . -6.98622 . . . 1.67967 . . . 2.469 . . . 6.89572 . . . 9.80855 . . . -0.882805 . . . 7.29114 . . . 8.81398 . . . 0.960449 . . . 2.38415 . . . 5.72287 . . . 0.477442 . . . 8.22189 . . . 1.26539 . . . 0.00331176 . . . -0.862402 . . . -1.78147 . . . 1.77879 . . . 5.62876 . . . 13.2257 . . . -2.25837 . . . 4.85454 . . . 7.75954 . . . -2.7965 . . . 5.40995 . . . -0.829046 . . . 1.96397 . . . -0.227596 . . . 7.99279 . . . 4.5132 . . . 8.40303 . . . 6.10705 . . . 7.57217 . . . 1.59191 . . . -4.86656 . . . 5.746 . . . 8.63338 . . . 7.34615 . . . 1.44182 . . . 1.82252 . . . -0.479249 . . . -4.83714 . . . 7.1351 . . . -2.09319 . . . 0.725358 . . . -1.94825 . . . 2.51755 . . . 9.52726 . . . 4.59317 . . . 1.64328 . . . -0.728129 . . . 0.996227 . . . 3.02028 . . . 5.83929 . . . 3.96691 . . . 8.96679 . . . 12.6762 . . . -2.84409 . . . 1.1741 . . . 6.25256 . . . 0.427056 . . . 2.03767 . . . 1.75351 . . . 0.918839 . . . 6.54883 . . . 4.63841 . . . 8.31167 . . . 6.63104 . . . 2.28408 . . . 7.62031 . . . 5.10859 . . . 5.17574 . . . 3.7369 . . . 9.65601 . . . 7.19025 . . . -1.66103 . . . 0.344304 . . . -0.989641 . . . 6.93493 . . . 9.97607 . . . -4.10632 . . . 4.31976 . . . 6.56731 . . . 4.61759 . . . 2.95938 . . . 3.64299 . . . 7.22476 . . . 4.47038 . . . 10.2559 . . . -3.28463 . . . 3.66494 . . . 9.94159 . . . -2.63448 . . . 1.37171 . . . -1.39587 . . . 5.13041 . . . 6.63742 . . . 17.2109 . . . 6.91036 . . . 3.04003 . . . 1.7727 . . . 13.6261 . . . 0.532953 . . . 5.42417 . . . 9.36241 . . . 8.70124 . . . -0.701276 . . . -1.30053 . . . 0.959223 . . . 0.984485 . . . 4.22582 . . . -5.67611 . . . 6.16331 . . . 4.49398 . . . 7.0969 . . . 3.07938 . . . 1.42093 . . . 4.30655 . . . 4.89669 . . . -0.0307035 . . . -2.44775 . . . -3.53927 . . . 4.95386 . . . 0.0656892 . . . 6.61006 . . . 0.229701 . . . 3.07183 . . . 7.19931 . . . 1.28336 . . . 2.52383 . . . 16.9326 . . . -2.56297 . . . 1.28687 . . . 7.13207 . . . 2.00515 . . . 8.41101 . . . 2.78254 . . . 1.22743 . . . -1.84455 . . . 2.21863 . . . 4.83492 . . . -1.39644 . . . 6.6403 . . . 6.95478 . . . -0.634291 . . . 5.79837 . . . 13.0093 . . . 7.67497 . . . -5.58749 . . . -1.06414 . . . 0.799215 . . . -9.8053 . . . 10.3389 . . . 6.87669 . . . 16.1577 . . . 13.0194 . . . 4.58741 . . . -6.30198 . . . -3.9074 . . . 6.25766 . . . -0.597703 . . . 9.61838 . . . 2.97375 . . . 5.36666 . . . 11.1641 . . . 5.2793 . . . 4.07542 . . . 5.61228 . . . 14.5815 . . . 1.09393 . . . 9.41281 . . . 7.05483 . . . 9.51357 . . . 6.33177 . . . 1.77391 . . . -2.53092 . . . -6.40177 . . . -2.26272 . . . 4.3088 . . . -2.04243 . . . 3.47024 . . . 1.75215 . . . 1.67921 . . . -4.09192 . . . 0.844261 . . . 7.73618 . . . 7.90815 . . . 7.48193 . . . 4.77235 . . . 5.50306 . . . -0.280026 . . . -2.29223 . . . 0.0207642 . . . 2.72275 . . . -1.59879 . . . -8.27077 . . . 2.99674 . . . 4.99576 . . . 5.1337 . . . -1.99057 . . . 5.64198 . . . 7.4133 . . . 1.97868 . . . 5.57715 . . . 2.15386 . . . 4.07239 . . . 1.37718 . . . 7.33425 . . . 3.00754 . . . 2.91419 . . . 8.8017 . . . 6.48088 . . . 2.93406 . . . 0.429028 . . . 4.15471 . . . -2.62293 . . . 5.69295 . . . 6.54764 . . . 3.151 . . . 17.9407 . . . 4.829 . . . 3.16595 . . . -0.702676 . . . 11.3251 . . . 6.40814 . . . -3.83111 . . . 1.48611 . . . 6.99451 . . . -3.96254 . . . 9.50163 . . . 10.4966 . . . 0.381975 . . . 0.0342817 . . . 7.44233 . . . 9.46625 . . . 4.67419 . . . 0.360632 . . . 5.68369 . . . 2.93473 . . . 11.969 . . . -3.13094 . . . 5.58538 . . . -2.66416 . . . -2.11765 . . . 0.066037 . . . 7.26846 . . . -4.79757 . . . 3.79095 . . . 1.58144 . . . -2.19757 . . . -0.847776 . . . 2.93504 . . . 16.3511 . . . -1.07993 . . . 3.21099 . . . 6.50544 . . . 6.54345 . . . -0.357147 . . . 2.7156 . . . 9.87162 . . . 1.157 . . . 4.83608 . . . 2.05112 . . . -2.7598 . . . -1.98578 . . . 7.93326 . . . 9.40445 . . . 5.29677 . . . 15.2367 . . . 4.91586 . . . 0.102431 . . . 6.42971 . . . -1.73494 . . . 0.806686 . . . -5.62456 . . . 6.05177 . . . 2.09602 . . . 2.5396 . . . 3.13864 . . . 4.79241 . . . 0.361129 . . . -1.2654 . . . 4.93499 . . . -1.08633 . . . 2.32421 . . . 3.49914 . . . 16.6805 . . . 5.55196 . . . 10.2856 . . . 4.07074 . . . 5.82233 . . . 13.0551 . . . 12.6633 . . . 8.43863 . . . 7.67436 . . . 1.59495 . . . 2.65994 . . . -3.64877 . . . 2.07206 . . . -3.55968 . . . 0.77158 . . . 8.84916 . . . 5.90046 . . . -1.80542 . . . -0.847434 . . . -5.30683 . . . -2.47321 . . . 5.62238 . . . -6.01847 . . . -1.61418 . . . 1.98479 . . . 4.03713 . . . 7.55194 . . . -4.09461 . . . 10.7847 . . . -3.75526 . . . -7.65194 . . . 1.12958 . . . 7.2438 . . . 4.4208 . . . -1.76135 . . . -3.5624 . . . 7.97048 . . . 9.24045 . . . 5.46799 . . . -10.0044 . . . 3.16039 . . . -0.744978 . . . 3.00142 . . . 6.53596 . . . -5.40545 . . . -3.03614 . . . 0.68561 . . . 3.97413 . . . 4.69861 . . . 0.398794 . . . -1.92813 . . . 3.16652 . . . -0.0314274 . . . 3.40283 . . . -5.55899 . . . 2.38821 . . . -3.08287 . . . 6.49844 . . . 7.35677 . . . 0.148269 . . . -1.06256 . . . 5.83094 . . . 4.79135 . . . -2.65242 . . . 10.1152 . . . -7.09422 . . . -0.810135 . . . 3.77165 . . . 2.65891 . . . 1.04598 . . . 4.45476 . . . -0.443756 . . . 2.85196 . . . 0.730403 . . . 3.81523 . . . -3.28452 . . . 1.1081 . . . 0.21903 . . . 0.170693 . . . -0.059689 . . . -3.86527 . . . 6.701 . . . -7.5268 . . . -3.36707 . . . 4.92761 . . . -1.42223 . . . 5.48212 . . . 3.52043 . . . -2.47874 . . . -3.36683 . . . 3.25991 . . . -1.54202 . . . 13.3732 . . . 4.8833 . . . 2.04018 . . . 8.09499 . . . 6.0457 . . . 3.98081 . . . 4.61499 . . . -1.87123 . . . 3.93954 . . . 2.94794 . . . 7.04596 . . . 0.730481 . . . -2.11278 . . . 2.23196 . . . -4.31973 . . . 6.45961 . . . 6.63914 . . . 4.55382 . . . -2.08655 . . . 1.60473 . . . -1.244 . . . 0.785804 . . . 6.86023 . . . 2.22092 . . . 11.8909 . . . 4.64095 . . . 0.803096 . . . -8.62668 . . . 10.0839 . . . 4.50328 . . . -3.37164 . . . 4.83504 . . . -4.83153 . . . 7.85538 . . . 1.52873 . . . 8.56527 . . . 8.34318 . . . 1.60007 . . . -15.0787 . . . 7.38113 . . . 7.51095 . . . 2.3078 . . . 13.0985 . . . -9.94614 . . . 3.07905 . . . -3.79791 . . . 0.320471 . . . 11.9925 . . . 2.55341 . . . 2.44292 . . . 8.35632 . . . 3.09602 . . . 8.54697 . . . 3.86024 . . . 1.93527 . . . 7.83949 . . . 7.49497 . . . 9.29011 . . . -2.85764 . . . 5.30247 . . . 10.6646 . . . -1.53976 . . . 10.0708 . . . 14.6495 . . . 4.89695 . . . 3.40384 . . . 4.63763 . . . -1.09618 . . . 3.26405 . . . -3.16104 . . . 5.47331 . . . 7.48144 . . . 1.11119 . . . 6.20366 . . . 1.13183 . . . -0.387414 . . . 2.51536 . . . -3.86906 . . . 6.69611 . . . 0.386987 . . . -2.93906 . . . 4.75712 . . . -6.81847 . . . 6.12929 . . . 8.2683 . . . 8.19087 . . . -3.71334 . . . 4.06695 . . . -2.01896 . . . 10.0248 . . . -1.19877 . . . 0.0148931 . . . -2.02945 . . . 0.883407 . . . 2.2449 . . . -5.27093 . . . 0.397495 . . . 1.23899 . . . 5.16289 . . . 2.74276 . . . 4.19835 . . . 7.0822 . . . 10.0155 . . . 5.06767 . . . 2.20119 . . . 8.00315 . . . -2.8813 . . . 7.6294 . . . 4.6375 . . . 2.86373 . . . -1.11619 . . . 4.27006 . . . 5.08784 . . . -1.18811 . . . 6.01643 . . . -1.15172 . . . -3.12389 . . . -5.9764 . . . 8.34282 . . . 2.77509 . . . 3.00163 . . . -2.19029 . . . -2.22301 . . . 1.44264 . . . -1.77913 . . . 0.216614 . . . 0.753233 . . . 4.50385 . . . -9.42315 . . . -2.92152 . . . 1.85109 . . . 13.3129 . . . 0.346376 . . . -0.836535 . . . 6.52977 . . . 5.50567 . . . 9.90263 . . . -0.25864 . . . 3.50462 . . . 0.200356 . . . 0.704986 . . . -2.3928 . . . 8.19287 . . . 4.14051 . . . 9.19013 . . . 11.6027 . . . -4.8553 . . . -0.0723119 . . . 4.94874 . . . 3.59557 . . . -7.81409 . . . 8.09155 . . . -5.70269 . . . 4.88826 . . . 2.97655 . . . 5.16623 . . . 11.8582 . . . 6.29054 . . . 3.09722 . . . 14.3898 . . . -3.27042 . . . -2.38691 . . . 7.28015 . . . -8.16032 . . . 0.769736 . . . 4.18418 . . . -7.79226 . . . -1.49691 . . . 7.75672 . . . -1.31928 . . . 1.57036 . . . -1.01939 . . . 2.15786 . . . 0.381793 . . . 4.83664 . . . -0.950607 . . . 3.47868 . . . 2.08851 . . . -4.63271 . . . -0.538706 . . . 9.37138 . . . -3.40408 . . . 3.86228 . . . 5.45387 . . . 4.78673 . . . 4.76204 . . . -10.0957 . . . 4.70046 . . . 6.32341 . . . 5.26029 . . . 6.7685 . . . 12.9345 . . . 2.66914 . . . 6.26752 . . . 1.79012 . . . -4.41312 . . . 1.38874 . . . 1.26646 . . . 0.504169 . . . -5.69204 . . . -1.80427 . . . 5.75696 . . . -9.96082 . . . 2.31294 . . . 3.94593 . . . 8.45618 . . . -0.128836 . . . -1.23137 . . . -0.000104058 . . . 0.215309 . . . -1.18051 . . . 3.87014 . . . 3.25954 . . . 7.30928 . . . 1.83235 . . . -2.94747 . . . -3.52098 . . . 4.06073 . . . 13.5516 . . . 3.6248 . . . -0.970285 . . . -1.58123 . . . 3.69858 . . . 2.49884 . . . -3.12202 . . . -3.31053 . . . -0.804416 . . . 10.3109 . . . 4.93254 . . . 13.3754 . . . 2.60561 . . . 2.43914 . . . 4.17908 . . . 5.16331 . . . 2.80255 . . . -0.0270132 . . . 7.02338 . . . 3.7276 . . . -1.04597 . . . -5.6513 . . . 14.7192 . . . 12.6056 . . . -1.70459 . . . 8.54151 . . . -6.14806 . . . 1.93799 . . . 4.90426 . . . 0.406391 . . . -9.19403 . . . 11.618 . . . 8.40702 . . . -0.0252943 . . . 1.03119 . . . -8.27304 . . . 3.20688 . . . 4.7939 . . . 9.19167 . . . -2.05354 . . . -0.928725 . . . -4.03757 . . . 2.77933 . . . 3.79918 . . . 3.38059 . . . 6.7392 . . . -1.53738 . . . 4.05471 . . . 4.47682 . . . 4.60288 . . . -1.02484 . . . 2.75551 . . . -1.97799 . . . 8.27853 . . . 0.882973 . . . -3.20029 . . . 3.49271 . . . 7.82419 . . . 3.56401 . . . 5.76026 . . . 2.78876 . . . 5.14653 . . . 5.42755 . . . 0.0777785 . . . 0.122056 . . . -1.65508 . . . 2.34176 . . . 5.05523 . . . 3.46376 . . . 1.63485 . . . 16.9926 . . . -2.8693 . . . 6.00097 . . . 7.44183 . . . 3.1163 . . . 13.5323 . . . 3.94052 . . . 2.77837 . . . 12.0541 . . . 3.78715 . . . -1.94643 . . . -3.53794 . . . 8.19962 . . . 1.6148 . . . 5.15792 . . . 5.88179 . . . 2.50385 . . . 1.19552 . . . -2.8522 . . . -2.40243 . . . 7.2097 . . . -2.90648 . . . 2.33745 . . . 16.3153 . . . -5.61542 . . . -7.66425 . . . -4.14941 . . . -1.53081 . . . -0.707977 . . . 11.4203 . . . 1.93908 . . . 0.89674 . . . 3.66745 . . . 6.90054 . . . 0.522798 . . . 3.22691 . . . -2.2971 . . . 2.86249 . . . 3.53524 . . . 4.86344 . . . 10.7571 . . . 3.66275 . . . 1.75058 . . . 4.01047 . . . 2.17885 . . . -5.49595 . . . 2.02935 . . . -1.23406 . . . 0.598466 . . . 13.2112 . . . 2.58819 . . . -4.92661 . . . -0.957909 . . . -1.68268 . . . -6.28497 . . . -2.38787 . . . 8.41993 . . . 0.786476 . . . -0.49089 . . . 2.98996 . . . 3.87743 . . . -3.79104 . . . -7.93041 . . . 2.24992 . . . 0.386846 . . . 0.514835 . . . 10.1213 . . . 3.19451 . . . 0.696892 . . . 15.1508 . . . 2.47696 . . . 8.49199 . . . 4.5253 . . . -5.68232 . . . 1.35116 . . . 10.3793 . . . -1.31543 . . . 4.52527 . . . -1.37757 . . . 9.51237 . . . -1.8002 . . . 4.58941 . . . 3.0354 . . . 5.57435 . . . 4.16988 . . . -2.18275 . . . -2.20276 . . . 7.41085 . . . -0.364016 . . . 5.54067 . . . 2.66615 . . . 2.24458 . . . -5.70987 . . . 4.35286 . . . 2.01125 . . . 1.0776 . . . -3.2808 . . . 14.0181 . . . 5.27767 . . . 3.83938 . . . 1.27255 . . . 1.74265 . . . 7.47889 . . . 3.42329 . . . 10.9307 . . . 13.1198 . . . -0.760015 . . . 5.37389 . . . 1.5137 . . . 3.60405 . . . -4.89223 . . . 1.14322 . . . -2.48603 . . . 4.99553 . . . 0.991866 . . . -3.99825 . . . 2.73104 . . . -0.255356 . . . 2.22947 . . . 8.53935 . . . -2.86676 . . . 9.34838 . . . 1.72308 . . . 10.9476 . . . 8.18254 . . . 5.7456 . . . -14.1881 . . . 8.84622 . . . 2.81141 . . . 7.82282 . . . -2.69119 . . . 7.37967 . . . 0.909316 . . . 7.40846 . . . 0.0618506 . . . 4.81075 . . . -3.03826 . . . 9.65405 . . . -5.57213 . . . 0.436228 . . . 13.8695 . . . -13.014 . . . 3.63518 . . . 0.31209 . . . 5.495 . . . -5.4404 . . . 3.61724 . . . -0.655386 . . . -4.8451 . . . 2.76398 . . . -0.15216 . . . 0.297629 . . . -2.70017 . . . 16.3214 . . . 8.88371 . . . 14.7433 . . . -1.75299 . . . 4.64817 . . . -2.03605 . . . 11.107 . . . 1.10624 . . . -2.97743 . . . -7.68144 . . . -4.27148 . . . 1.57378 . . . 10.2729 . . . 3.14541 . . . 0.0192914 . . . -2.08261 . . . 2.87933 . . . -1.05385 . . . 1.31623 . . . 5.57773 . . . 5.58005 . . . 5.80864 . . . 4.89186 . . . 0.750444 . . . 5.22841 . . . 2.53075 . . . 6.02149 . . . -5.35961 . . . 3.35091 . . . -0.440386 . . . -3.81744 . . . 2.81925 . . . 11.0715 . . . 11.4335 . . . -2.58458 . . . 8.38671 . . . 2.00568 . . . 1.79628 . . . 2.82573 . . . -13.4693 . . . -3.5426 . . . 8.84533 . . . 3.95973 . . . 4.06755 . . . 4.88401 . . . -0.247346 . . . 0.523174 . . . 5.676 . . . 8.30839 . . . 9.0413 . . . 3.3994 . . . 4.91682 . . . 7.24873 . . . -1.43301 . . . 7.8025 . . . 7.5423 . . . 2.75903 . . . 7.58182 . . . 2.98437 . . . 0.378904 . . . 6.44871 . . . 5.55394 . . . 4.6892 . . . 4.00045 . . . 4.46557 . . . -0.837075 . . . -0.183045 . . . 10.3146 . . . 5.18402 . . . -2.72874 . . . -1.93695 . . . -1.48301 . . . -4.52271 . . . 6.30108 . . . 6.62773 . . . 9.34725 . . . -2.13939 . . . 2.40386 . . . 1.96649 . . . -1.43589 . . . 0.661174 . . . 3.55437 . . . 4.84007 . . . 8.9043 . . . 4.4478 . . . -1.62999 . . . 0.939083 . . . 4.15381 . . . 3.15783 . . . -0.917657 . . . 7.41529 . . . 6.95622 . . . 3.67557 . . . -4.17865 . . . 4.22084 . . . -1.90243 . . . 0.0800052 . . . 3.15062 . . . 6.15506 . . . 7.11051 . . . 4.88896 . . . 6.14606 . . . 2.83718 . . . -5.11863 . . . 8.15625 . . . -0.606506 . . . 5.21045 . . . 5.56411 . . . 6.64461 . . . 7.54436 . . . -4.67392 . . . 0.918768 . . . 1.0247 . . . 7.08034 . . . -1.74587 . . . 10.8287 . . . 1.92808 . . . 2.77865 . . . 2.42304 . . . -10.6486 . . . 6.48319 . . . 1.21831 . . . 0.483139 . . . -0.330745 . . . 5.46917 . . . 0.498351 . . . -2.22322 . . . -0.33823 . . . 8.47773 . . . 1.58139 . . . -3.03311 . . . 2.96334 . . . 4.60556 . . . 12.4212 . . . -0.722704 . . . 7.09266 . . . 7.10743 . . . 11.1913 . . . 0.467633 . . . 4.26159 . . . 5.81701 . . . 4.0251 . . . 11.2504 . . . 1.56848 . . . 4.86858 . . . 10.8577 . . . 0.579944 . . . 1.01292 . . . 2.25243 . . . 0.0301081 . . . 7.98167 . . . -3.29544 . . . 6.26787 . . . 15.4856 . . . 0.801795 . . . -4.21455 . . . 0.715982 . . . 8.40519 . . . 13.0467 . . . -0.517143 . . . -1.17268 . . . 3.70708 . . . 12.8783 . . . 5.81049 . . . 9.80132 . . . -5.2181 . . . 6.26015 . . . -1.60289 . . . 12.7418 . . . -4.06368 . . .
SAS Super FREQ

Re: simulatiom data with sas/iml

You have defined the macro variable &N, but there is no value for N.

Use

eps = j(&N, 3);

Calcite | Level 5

Re: simulatiom data with sas/iml

thank you dr. for your help i have been  changed this value to &N and i dont see error in sas log but i dont get on values for x1-x3 still missing .

%let N=1000;

proc iml;

/* specify the mean and covariance of the population */

Mean = {1, 2, 3};

Cov = {3 2 1,

2 4 0,

1 0 5};

call randseed(4321);

X = RandNormal(&N, Mean, Cov);               /* 1000 x 3 matrix     */

eps = j(&N, 3);                           /* allocate N x 3 vector   */

call randgen(eps, "Normal", 0, 1);   /* fill with random normal */

beta = {2, 1, -1};                      /* params, not including intercept */

eta = X*beta;                            /* linear predictor        */

Y = eta + eps;                            /* three simulated response  */

/* write SAS data set */

varNames = ('x1':'x3') || {"Y"};

output = X || Y;

create SimReg var {Y X1 X2 X3};  append;  close SimReg; /* write data */

run;

SAS Super FREQ

Re: simulatiom data with sas/iml

Try this:

eps = j(&N, 1);                           /* allocate N x 3 vector   */

call randgen(eps, "Normal", 0, 1);   /* fill with random normal */

Y = eta + eps;                            /* three simulated response  */

varNames = ('x1':'x3') || {"Y"};

output = X || Y;

create SimReg from output[c=varNames];  append from output;  close SimReg; /* write data */

You say that you have my book Simulating Data with SAS, but I think that you need to read the words that accompany the programs, rather than just try to modify programs without understanding how they work. Taking the time to understnad the programs in the book will pay off when you start modifying them.

Good luck.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
• 12 replies
• 1551 views
• 3 likes
• 3 in conversation