I'm trying to generate a data set with 1,000 observations with random integers from 1 to 5. Does anyone know how I would do this using the rand function?
Here's the question posed:
Create a temporary SAS data set (Random) consisting of 1,000 observations, each
with a random integer from 1 to 5. Make sure that all integers in the range are
equally likely. Run PROC FREQ to test this assumption
try this:
data have;
do i=1 to 1000;
x=int(rand('uniform')*5)+1;output ;end;
run;
proc freq;
tables x/missing;
run;
Cumulative Cumulative
x Frequency Percent Frequency Percent
1 200 20.00 200 20.00
2 216 21.60 416 41.60
3 203 20.30 619 61.90
4 187 18.70 806 80.60
5 194 19.40 1000 100.00
or x = ceil(5*rand("UNIFORM"));
PG
THank you very much!!
I would use table distribution but what do I know.
rand('TABLE',.2,.2,.2,.2);
Most useful I suppose if you want to fiddle with the probs.
One method which assures exactly equal likelihoods:
data notrandom ;
do val = 1 to 5 ; do rep = 1 to 200 ;
order = ranuni(2468) ;
output ;
end ; end ;
run ;
proc sort data=notrandom out=random(keep=val) ;
by order ;
run ;
proc freq data=random ; run ;
pma85 wrote:
I'm trying to generate a data set with 1,000 observations with random integers from 1 to 5. Does anyone know how I would do this using the rand function?
Here's the question posed:
Create a temporary SAS data set (Random) consisting of 1,000 observations, each
with a random integer from 1 to 5. Make sure that all integers in the range are
equally likely. Run PROC FREQ to test this assumption
Howles, that technique generates a random ordering, not random values. Given any subset of 999 values from that set, the 1000th value is known without error. In other words, the values are not totally independent.
PG
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.