Help using Base SAS procedures

Random number generation as a new variable

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Random number generation as a new variable

Hello seniors -

I want to add a column called RandomNumber (say Z) to my existing list of variables (X Y).

Similar to way we generate a random number in excel using command =Rand().

Thanks for advise.

R


Accepted Solutions
Solution
‎08-28-2012 07:31 PM
Respected Advisor
Posts: 4,930

Re: Random number generation as a new variable

The RAND function in SAS has arguments. For uniformly distributed values similar to the RAND() function in Excel do:

data want;

set have;

Z = RAND("UNIFORM");

run;

PG

PG

View solution in original post


All Replies
Solution
‎08-28-2012 07:31 PM
Respected Advisor
Posts: 4,930

Re: Random number generation as a new variable

The RAND function in SAS has arguments. For uniformly distributed values similar to the RAND() function in Excel do:

data want;

set have;

Z = RAND("UNIFORM");

run;

PG

PG
Contributor
Posts: 29

Re: Random number generation as a new variable

Hi PG,

I used the following, I am newbie and am sure missing something basic. Can you please gide?

data carslist;

     set data=sashelp.cars;

     z=rand('UNIFORM');

run;

Thanks

R

Respected Advisor
Posts: 4,930

Re: Random number generation as a new variable

Remove the data=

data carslist;

     set sashelp.cars;

     z=rand('UNIFORM');

run;

PG

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 178 views
  • 0 likes
  • 2 in conversation