BookmarkSubscribeRSS Feed
asayin
Calcite | Level 5

I want to generating data with a known correlation structure. I use proc iml and this codes.

proc iml;

  n = 5;

  r = {1 .07 .25 .6, .07 1 .07 .25, .25 .07 1 .07, .6 .25 .07 1};

  print r;

  c = root(r);

  print c;

  z=j(n,4,.);

    do i = 1 to n;

                  do j = 1 to 4;

                   z[i,j]=rannor(-99);

                  end;

                end;

  print z;  

  d = z*c;

  print d;

  x1 = d[,1];  x2=d[,2]; x3=d[,3]; x4=d[,4];

  print x1 x2 x3 x4;

  create mvn var{x1 x2 x3 x4};

  append;

quit;

proc print data = mvn;

run;

It is okey but I want to iteration. I've tried many codes, but so far I did not succeed. How can I make 20 replicate?


And also I want to generate ordinal data. How I can do it?

Thanks for your help...

1 REPLY 1
Rick_SAS
SAS Super FREQ

It looks like your code is for the multivariate normal case. You can simplify your life by using the built-in RANDNORMAL function.

For your other two questions, you might want to look at my book Simulating Data with SAS.

Chapter 8 deals with simulating MV data from standard distributions. For the MVN case, you can generate 20 replicates like this:

NumSamples = 20;

Mean = j(1,4,0);

x = RandNormal( NumSamples*N, Mean, R);

ID = colvec(repeat( T(1:NumSamples), 1, N));

Y = ID || x;

varNames = "x1":"x4";

create MVN from Y[c=("ID"||varNames)];

append from Y;

close MVN;

The case of ordinal variables is described in Chapter 9.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1 reply
  • 408 views
  • 1 like
  • 2 in conversation