turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Ranuni ( )

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-15-2009 09:07 AM

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 !

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 !

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KevinC_

10-15-2009 09:35 AM

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!

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KevinC_

10-15-2009 10:34 AM

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)."

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)."

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KevinC_

10-15-2009 10:49 AM

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]

[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]

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to data_null__

10-15-2009 11:20 AM

Thank you both for your input !