BookmarkSubscribeRSS Feed
thanoon
Calcite | Level 5

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
Rick_SAS
SAS Super FREQ

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.

thanoon
Calcite | Level 5

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

thanoon
Calcite | Level 5

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;

Rick_SAS
SAS Super FREQ

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.

thanoon
Calcite | Level 5

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

thanoon
Calcite | Level 5

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

TomTom
Calcite | Level 5

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.

thanoon
Calcite | Level 5

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

regards

thanoon
Calcite | Level 5

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.0639615034...
8.7604741298...
-5.035401045...
5.0681522716...
-1.434494564...
4.2888670546...
0.3437352408...
0.1903218603...
7.7486286899...
9.1305794419...
8.7890734264...
-6.986217139...
1.6796699989...
2.4689960048...
6.8957207877...
9.8085514567...
-0.882804893...
7.2911410264...
8.8139808689...
0.960449155...
2.3841493468...
5.7228733982...
0.4774421808...
8.2218934396...
1.2653875237...
0.0033117611...
-0.862401541...
-1.781473491...
1.7787899373...
5.628762229...
13.225739198...
-2.258366947...
4.8545383166...
7.7595357105...
-2.796501042...
5.4099479113...
-0.829046056...
1.963970842...
-0.227596273...
7.9927922196...
4.513202938...
8.4030329473...
6.1070483351...
7.5721735763...
1.5919142611...
-4.866557519...
5.7460043819...
8.6333773989...
7.3461513714...
1.4418196688...
1.8225161389...
-0.479248889...
-4.837137342...
7.1350996279...
-2.093186425...
0.7253583126...
-1.94825457...
2.5175477491...
9.5272630459...
4.5931729633...
1.6432755849...
-0.728129041...
0.9962266665...
3.0202785339...
5.8392927167...
3.9669077737...
8.9667914641...
12.676193691...
-2.844085692...
1.1740975854...
6.2525591414...
0.4270564391...
2.037666801...
1.7535131864...
0.9188388142...
6.5488345962...
4.6384050645...
8.3116687432...
6.631042728...
2.2840760125...
7.6203094383...
5.1085940112...
5.1757393859...
3.7369015894...
9.6560104014...
7.1902492712...
-1.661028363...
0.3443035314...
-0.98964097...
6.934934255...
9.976071633...
-4.106320022...
4.3197604149...
6.5673064812...
4.6175869476...
2.9593775686...
3.642987328...
7.2247567623...
4.4703829728...
10.255933881...
-3.284627476...
3.6649419708...
9.9415914824...
-2.634481615...
1.3717099154...
-1.39587437...
5.1304056345...
6.6374190826...
17.210877049...
6.9103581478...
3.0400266802...
1.7727040724...
13.626099312...
0.5329531336...
5.4241728288...
9.3624103949...
8.7012389804...
-0.701275878...
-1.30052752...
0.9592230598...
0.9844845326...
4.2258228921...
-5.676105979...
6.1633107146...
4.4939838231...
7.0969016867...
3.0793827816...
1.4209334038...
4.3065503501...
4.8966924258...
-0.030703477...
-2.447752486...
-3.539269962...
4.9538586148...
0.0656891806...
6.6100640986...
0.22970129...
3.071826821...
7.1993109972...
1.2833564811...
2.523830943...
16.932628284...
-2.562968143...
1.2868670266...
7.1320697627...
2.0051530342...
8.4110136723...
2.7825418594...
1.2274256325...
-1.84454786...
2.2186300674...
4.8349233481...
-1.396439505...
6.6403006506...
6.9547786533...
-0.634290772...
5.7983720682...
13.009295621...
7.6749677599...
-5.587491506...
-1.064142293...
0.7992153589...
-9.805297102...
10.338944207...
6.8766901506...
16.157689251...
13.019401747...
4.5874111322...
-6.301975875...
-3.907404384...
6.2576577622...
-0.597703496...
9.6183752214...
2.9737461653...
5.3666571855...
11.164119237...
5.2793040293...
4.0754173015...
5.6122761015...
14.581534023...
1.0939280179...
9.4128071487...
7.0548315973...
9.5135718589...
6.331772276...
1.7739102922...
-2.530921318...
-6.401771126...
-2.262719847...
4.3087962942...
-2.042430273...
3.4702375779...
1.7521515507...
1.6792056829...
-4.091921922...
0.8442609285...
7.7361832589...
7.9081460274...
7.4819348439...
4.7723524795...
5.5030615216...
-0.280025745...
-2.292231851...
0.0207642278...
2.7227462109...
-1.598789682...
-8.270772956...
2.9967435874...
4.9957623825...
5.1337019643...
-1.990574228...
5.6419792318...
7.4133032877...
1.9786779706...
5.5771481155...
2.1538576105...
4.072394721...
1.3771811572...
7.3342476983...
3.007537005...
2.9141940978...
8.8017042945...
6.4808830353...
2.9340559404...
0.4290275912...
4.154706247...
-2.622931502...
5.6929454368...
6.5476352853...
3.1510040918...
17.940725125...
4.8290041084...
3.1659478785...
-0.702675682...
11.325114914...
6.4081386731...
-3.831114684...
1.4861119069...
6.9945056051...
-3.962544539...
9.501626488...
10.496569988...
0.381975493...
0.0342816733...
7.4423314784...
9.4662536559...
4.6741855025...
0.3606317103...
5.6836889524...
2.934732126...
11.969047124...
-3.130943982...
5.5853781506...
-2.664156455...
-2.117649487...
0.066037029...
7.2684576659...
-4.797570252...
3.7909498531...
1.5814368686...
-2.197570736...
-0.847775608...
2.9350355607...
16.351093212...
-1.079928337...
3.2109857745...
6.5054401209...
6.5434450778...
-0.357147455...
2.7155973709...
9.8716198569...
1.1569953152...
4.8360839906...
2.0511195101...
-2.759800748...
-1.985779976...
7.9332613166...
9.4044487235...
5.2967718373...
15.236690563...
4.9158575422...
0.1024307859...
6.4297057978...
-1.734937114...
0.8066864231...
-5.624563411...
6.0517670897...
2.0960161499...
2.5396046387...
3.1386442325...
4.79240911...
0.361128633...
-1.265401637...
4.9349896649...
-1.086332877...
2.3242093742...
3.499136374...
16.680471291...
5.5519562127...
10.285628561...
4.0707414007...
5.8223281248...
13.055077906...
12.663339821...
8.4386260099...
7.6743577367...
1.5949498734...
2.659936537...
-3.648766369...
2.0720583516...
-3.559675166...
0.7715801904...
8.8491580473...
5.9004583829...
-1.805417349...
-0.847434182...
-5.30682732...
-2.473210558...
5.6223790943...
-6.018471671...
-1.614179169...
1.9847863801...
4.0371255428...
7.5519411899...
-4.094608656...
10.784694995...
-3.755259395...
-7.651938345...
1.1295841099...
7.243800466...
4.4208027944...
-1.761345699...
-3.562399448...
7.9704806907...
9.2404467587...
5.4679891997...
-10.00435073...
3.1603858603...
-0.744978251...
3.0014245391...
6.5359647615...
-5.405452958...
-3.036138424...
0.6856096966...
3.9741294337...
4.6986102646...
0.3987942967...
-1.928128606...
3.1665180787...
-0.031427404...
3.4028281624...
-5.55899328...
2.3882099583...
-3.082868925...
6.4984430454...
7.3567681453...
0.1482691479...
-1.062561267...
5.8309353964...
4.7913547251...
-2.652415389...
10.115160215...
-7.094224997...
-0.810135099...
3.7716482475...
2.6589053897...
1.0459760768...
4.4547554671...
-0.44375581...
2.8519592864...
0.7304029554...
3.8152283532...
-3.284522742...
1.1080977327...
0.2190304604...
0.1706927182...
-0.059689024...
-3.865269199...
6.700997273...
-7.526799361...
-3.36706802...
4.9276050805...
-1.422226254...
5.4821243965...
3.5204287475...
-2.478741168...
-3.366830798...
3.2599134976...
-1.542018331...
13.37323658...
4.8832952631...
2.0401836265...
8.0949924864...
6.0457046445...
3.980812397...
4.614993469...
-1.871225476...
3.9395444285...
2.9479361313...
7.0459598602...
0.7304813119...
-2.112777144...
2.2319594913...
-4.319732092...
6.4596063276...
6.6391428145...
4.5538213821...
-2.086551957...
1.6047328263...
-1.244003777...
0.7858039406...
6.8602321826...
2.2209221222...
11.890905136...
4.6409511641...
0.8030957112...
-8.626682083...
10.083898256...
4.5032750468...
-3.371636792...
4.8350442181...
-4.831533229...
7.855379233...
1.528728445...
8.5652740497...
8.3431847036...
1.600069532...
-15.07865842...
7.381129651...
7.510946065...
2.3078033224...
13.09851533...
-9.946138445...
3.0790497952...
-3.797909167...
0.3204710931...
11.992464183...
2.553412696...
2.4429182438...
8.3563216972...
3.0960187877...
8.546972687...
3.8602391474...
1.9352693107...
7.8394876679...
7.4949706404...
9.2901145404...
-2.857639282...
5.3024718741...
10.664595695...
-1.539756736...
10.070782282...
14.649457357...
4.89694986...
3.4038433529...
4.6376331976...
-1.096176752...
3.2640529749...
-3.161040835...
5.4733147408...
7.4814441241...
1.1111883355...
6.2036582458...
1.1318327469...
-0.387414364...
2.5153571378...
-3.869058544...
6.6961076925...
0.3869871833...
-2.939063626...
4.7571244575...
-6.818471227...
6.1292888797...
8.268303159...
8.1908654245...
-3.713343733...
4.0669502237...
-2.018960876...
10.024825429...
-1.198765885...
0.014893108...
-2.02945328...
0.8834073174...
2.2448952979...
-5.270931699...
0.3974952164...
1.2389909224...
5.1628864328...
2.742761933...
4.1983545686...
7.0821973655...
10.015451876...
5.0676677259...
2.2011948836...
8.0031545362...
-2.881304207...
7.6294023315...
4.637504891...
2.8637317214...
-1.116190311...
4.2700585193...
5.0878385684...
-1.188110079...
6.0164304054...
-1.151724564...
-3.123892425...
-5.976404165...
8.3428236301...
2.7750880857...
3.0016331441...
-2.190285283...
-2.223010941...
1.4426357512...
-1.779134852...
0.2166139802...
0.7532329025...
4.5038486474...
-9.423153912...
-2.92151953...
1.8510896468...
13.312904604...
0.3463756258...
-0.836534511...
6.5297657739...
5.5056667625...
9.9026327866...
-0.258640027...
3.5046163249...
0.2003559811...
0.7049864651...
-2.392801444...
8.1928672328...
4.1405120339...
9.1901272035...
11.602665924...
-4.855302395...
-0.072311859...
4.9487429211...
3.5955669388...
-7.814093491...
8.0915469593...
-5.702690347...
4.8882621645...
2.9765457498...
5.1662273875...
11.858152724...
6.2905413778...
3.0972209962...
14.389834048...
-3.270420285...
-2.38691182...
7.2801525729...
-8.160322186...
0.7697363901...
4.1841800675...
-7.792256137...
-1.496912889...
7.7567249746...
-1.319276209...
1.5703574254...
-1.019389327...
2.1578596303...
0.3817934483...
4.8366424672...
-0.950607115...
3.4786791516...
2.0885083053...
-4.632713668...
-0.538706303...
9.3713766031...
-3.404081168...
3.8622807984...
5.4538669594...
4.7867261851...
4.7620416513...
-10.09572286...
4.7004612008...
6.3234062222...
5.2602898681...
6.7684952261...
12.934462197...
2.669141594...
6.267522897...
1.7901209994...
-4.413124792...
1.3887413206...
1.2664646409...
0.5041693279...
-5.692043946...
-1.804268766...
5.7569633382...
-9.960821901...
2.3129423487...
3.9459251845...
8.4561816559...
-0.128835825...
-1.23136797...
-0.000104058...
0.2153091278...
-1.18050522...
3.8701422777...
3.2595422992...
7.3092823217...
1.8323469057...
-2.947469443...
-3.520983073...
4.0607266994...
13.551577552...
3.6247950169...
-0.970284965...
-1.581227559...
3.6985790652...
2.4988420095...
-3.122020709...
-3.310533279...
-0.804415665...
10.310855472...
4.9325372907...
13.37542627...
2.6056097654...
2.4391391565...
4.1790765161...
5.1633056935...
2.8025507011...
-0.027013226...
7.0233848529...
3.727601906...
-1.045971486...
-5.651304633...
14.719164161...
12.605641764...
-1.704589419...
8.5415135605...
-6.148055296...
1.9379933276...
4.9042603669...
0.406391081...
-9.194032448...
11.617974265...
8.4070176857...
-0.025294312...
1.0311891002...
-8.2730437...
3.2068777297...
4.7939048242...
9.1916682745...
-2.053543239...
-0.928725077...
-4.037572752...
2.7793312105...
3.799177299...
3.3805919423...
6.7391997138...
-1.537375212...
4.0547124462...
4.4768194444...
4.6028845044...
-1.0248416...
2.755514041...
-1.977985734...
8.2785323335...
0.8829726374...
-3.200288837...
3.4927057611...
7.8241899592...
3.5640113939...
5.7602563457...
2.7887600133...
5.1465316083...
5.4275494529...
0.0777785266...
0.1220560553...
-1.655076334...
2.3417638753...
5.0552270671...
3.4637635403...
1.6348498087...
16.992616913...
-2.86929704...
6.0009749902...
7.4418256883...
3.1162954073...
13.532298499...
3.9405200413...
2.7783661469...
12.054121801...
3.7871549272...
-1.946427719...
-3.537938573...
8.1996154764...
1.6148030042...
5.1579194026...
5.8817913485...
2.5038545714...
1.1955189684...
-2.852204661...
-2.402431307...
7.2097009481...
-2.906482011...
2.3374467141...
16.315257898...
-5.615416505...
-7.664251947...
-4.149413101...
-1.530812021...
-0.707976969...
11.420296379...
1.9390758961...
0.8967404005...
3.667454351...
6.9005432383...
0.5227982935...
3.226911906...
-2.297095694...
2.8624921578...
3.5352365016...
4.863444104...
10.757120545...
3.6627502943...
1.7505829197...
4.0104702836...
2.1788505284...
-5.495949097...
2.029350365...
-1.234062472...
0.5984664574...
13.211199098...
2.5881905553...
-4.926611422...
-0.957908667...
-1.682680145...
-6.284973496...
-2.387868857...
8.4199330745...
0.7864759486...
-0.490889908...
2.9899611609...
3.8774342717...
-3.791036564...
-7.930413578...
2.2499187298...
0.3868462213...
0.5148346593...
10.121324257...
3.1945121581...
0.6968920131...
15.150774391...
2.4769554431...
8.4919903044...
4.5252953867...
-5.682320197...
1.3511606475...
10.379255676...
-1.315428112...
4.5252697557...
-1.377569045...
9.512365991...
-1.800199978...
4.5894066316...
3.0353979684...
5.5743496056...
4.169876464...
-2.18275269...
-2.20276004...
7.4108496989...
-0.364015546...
5.5406715832...
2.6661537477...
2.2445825547...
-5.70987104...
4.3528604239...
2.0112528782...
1.0775965186...
-3.280802036...
14.018109379...
5.277672224...
3.839376403...
1.2725459056...
1.7426474345...
7.4788880594...
3.4232932924...
10.93071522...
13.119790477...
-0.760015184...
5.3738909471...
1.5136981215...
3.604051495...
-4.892234835...
1.1432162353...
-2.486025391...
4.995530785...
0.9918663771...
-3.998246971...
2.7310363507...
-0.255355545...
2.229467609...
8.5393533056...
-2.866762719...
9.3483789381...
1.7230814578...
10.947587809...
8.1825418158...
5.7456034844...
-14.18807186...
8.8462219984...
2.8114074722...
7.8228204352...
-2.691194275...
7.3796741123...
0.9093164088...
7.408455634...
0.0618506341...
4.8107534442...
-3.038259229...
9.6540455863...
-5.572130329...
0.4362284671...
13.869523711...
-13.01397628...
3.6351838428...
0.3120898875...
5.4949982827...
-5.440401344...
3.6172409034...
-0.655385748...
-4.845098622...
2.7639798849...
-0.152159979...
0.2976290338...
-2.70017239...
16.321424255...
8.88370628...
14.74329447...
-1.752994743...
4.6481650744...
-2.036049493...
11.107003706...
1.1062382271...
-2.977428675...
-7.681440196...
-4.271482268...
1.5737772625...
10.272881626...
3.1454055035...
0.0192914445...
-2.082605285...
2.8793296794...
-1.053847439...
1.3162255066...
5.5777288727...
5.5800515315...
5.8086350271...
4.8918618108...
0.7504440515...
5.2284087545...
2.5307496496...
6.0214888524...
-5.359606567...
3.3509051018...
-0.440386373...
-3.817444756...
2.8192515261...
11.071486449...
11.433515936...
-2.584578872...
8.3867101409...
2.005677374...
1.7962756876...
2.8257270912...
-13.46928184...
-3.542600808...
8.8453328487...
3.9597348463...
4.0675460414...
4.8840053936...
-0.247346271...
0.5231735552...
5.675999563...
8.3083886577...
9.0412965915...
3.3994018676...
4.9168248594...
7.2487310457...
-1.433005797...
7.8025025841...
7.5422964545...
2.7590289721...
7.5818223234...
2.9843651371...
0.3789040699...
6.4487072038...
5.5539447008...
4.6892016086...
4.000453716...
4.4655669353...
-0.837074604...
-0.183045317...
10.31463627...
5.1840242128...
-2.728735686...
-1.936949797...
-1.483011507...
-4.522714415...
6.3010841903...
6.6277345992...
9.347245452...
-2.139392368...
2.4038602371...
1.966488936...
-1.43589197...
0.6611739208...
3.5543675447...
4.840067845...
8.9043024772...
4.4478002708...
-1.629994711...
0.9390828246...
4.1538099902...
3.1578311...
-0.91765669...
7.4152862918...
6.9562230623...
3.6755673455...
-4.178650464...
4.2208379399...
-1.902426707...
0.080005186...
3.1506167306...
6.1550583987...
7.1105129118...
4.8889620026...
6.1460571017...
2.8371805396...
-5.118627684...
8.1562511452...
-0.606506488...
5.2104501847...
5.5641139607...
6.644607167...
7.5443553387...
-4.673924743...
0.9187677335...
1.0247047228...
7.0803361247...
-1.745872855...
10.828710455...
1.9280750113...
2.778651456...
2.4230445861...
-10.64858879...
6.4831867269...
1.2183125368...
0.4831391118...
-0.330745217...
5.4691651455...
0.4983508831...
-2.223222974...
-0.33822967...
8.4777314866...
1.5813929961...
-3.033114853...
2.9633393454...
4.6055604455...
12.421196567...
-0.722703529...
7.0926632468...
7.107432267...
11.19132548...
0.4676334475...
4.2615895538...
5.8170106309...
4.0250983833...
11.250415309...
1.5684838474...
4.8685754054...
10.857711907...
0.5799437078...
1.0129190337...
2.2524318424...
0.0301081471...
7.9816717425...
-3.295444304...
6.2678653957...
15.485559886...
0.8017946523...
-4.214551404...
0.7159823612...
8.4051945805...
13.046650804...
-0.517142754...
-1.172676092...
3.7070838872...
12.878311469...
5.8104853282...
9.8013191595...
-5.218095819...
6.2601487559...
-1.602887697...
12.741843166...
-4.063682834...
Rick_SAS
SAS Super FREQ

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

Use

eps = j(&N, 3);

thanoon
Calcite | Level 5

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;

Rick_SAS
SAS Super FREQ

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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