BookmarkSubscribeRSS Feed
KevinC_
Fluorite | Level 6
Hello,

I hope I posted this in the right forum. I am trying to figure out how RANUNI works in the following pgm.

Data BB (drop=ran1);
set AA;
ran1=ranuni(1234);
if ran1 < 0.50 then do;
test_cell = 'PM400';
end;

else if ran1 >= 0.50 then do;
test_cell = 'PM401';
end;
run;


Proc Freq data = BB; tables test_cell;

** here is the part of the output that I dont understand*****

test_cell frequency percent
------------------------------------------------
PM400 4194 50.65
PM401 4087 49.35


I understand RANUNI assignes a random number to a variable, in this case 'ran1'. But how does the value of 'ran1' control what records get what test_cell?

Thank you so much for any input !
4 REPLIES 4
KevinC_
Fluorite | Level 6
let me rephrase my question a little:

according to the result (50.65% vs 49.35%) I can see that the value of 'ran1' was evenly distributed between < 0.50 and >= 0.50. Why is that? Is this by design?

Thanks!
Doc_Duke
Rhodochrosite | Level 12
Yes, it is by design. RANUNI() is one of many pseudo random number generators in SAS. In particular, RANUNI is designed to generate pseudo random numbers on the real line between 0 and 1 with a uniform distribution.

From the 9.1.3 documentaiton, "The RANUNI function returns a number that is generated from the uniform distribution on the interval (0,1) using a prime modulus multiplicative generator with modulus 231- and multiplier 397204094 (Fishman and Moore 1982) (See References)."
data_null__
Jade | Level 19
To me the RANTBL function makes this much easier.

[pre]
Data BB;
/*set AA;*/
do id = 1 to 100;
*ran1=ranuni(1234);
*if ran1 < 0.50 then test_cell = 'PM400';
*else if ran1 >= 0.50 then test_cell = 'PM401';

ran1 = rantbl(1234,.5);
length test_cell $5;
test_cell = scan('PM400 PM401',ran1);
output;
end;
run;
Proc Freq data = BB; tables test_cell;
run;
[/pre]
KevinC_
Fluorite | Level 6
Thank you both for your input !

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!

What is Bayesian Analysis?

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.

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
  • 4 replies
  • 4720 views
  • 0 likes
  • 3 in conversation