I want to generate a data set from scratch that has j number of variables (n=10) and i number of observations (n=100) with random numbers populating each variable. I have attempted to run do loops, but I am not sure how to incorporate randgen into the code to get random observations.
If anyone can help point me in the right direction I'd appreciate it!
http://blogs.sas.com/content/iml/2011/08/24/how-to-generate-random-numbers-in-sas.html
Are you intending to work in IML or Base?
Base
I'm fairly sure that RANDGEN is an IML function not base.
In Base, you can use RAND.
data want;
array myRand(10);
do nrows=1 to 100;
do nvars=1 to dim(myRand);
myRand(i) = rand('normal', 50, 2);
end;
output;
end;
run;
I got an error with that code:
ERROR: Array subscript out of range at line 6 column 14.
@MikeBurton wrote:
I got an error with that code:
ERROR: Array subscript out of range at line 6 column 14.
An error message without code doesn't help much. Post the log with the code and error into a code box opened with the forum {i} menu icon so we have chance of finding column 14. The forum will reformat text in the main message window.
it was from the code Reeza posted above:
data want; array myRand(10); do nrows=1 to 100; do nvars=1 to dim(myRand); myRand(i) = rand('normal', 50, 2); end; output; end; run;
Error from log:
1 data want; 2 array myRand(10); 3 4 do nrows=1 to 100; 5 do nvars=1 to dim(myRand); 6 myRand(i) = rand('normal', 50, 2); 7 end; 8 output; 9 end; 10 run; NOTE: Variable i is uninitialized. ERROR: Array subscript out of range at line 6 column 14. myRand1=. myRand2=. myRand3=. myRand4=. myRand5=. myRand6=. myRand7=. myRand8=. myRand9=. myRand10=. nrows=1 nvars=1 i=. _ERROR_=1 _N_=1 NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 13 variables. NOTE: DATA statement used (Total process time): real time 0.19 seconds cpu time 0.01 seconds
i should be Nvar
yes, that works now - exactly what I needed. Thanks Reeza
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.
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.