```Date: Thu, 26 Jul 2007 09:36:44 -0700 Reply-To: webonomic Sender: "SAS(r) Discussion" From: webonomic Organization: http://groups.google.com Subject: Re: Generate observations with a specific range of randomly chosen values Comments: To: sas-l@uga.edu In-Reply-To: <1185465164.917924.145350@k79g2000hse.googlegroups.com> Content-Type: text/plain; charset="us-ascii" Thanks, that helped me figure out what I need and it also lead me to research more about RANUNI. I did the following and it seems to work: data a; do i=1 to 20; x=floor(ranuni(8)*4)+1; y=floor(ranuni(8)*2)+0; if y=0 then z=floor(ranuni(8)*3)+1; else z=floor(ranuni(8)*3)+4; output; end; run; At first I thought something was wrong because the value of 6 was not chosen for Z but all I needed was to create more observations (do i=1 to 100). Jared On Jul 26, 9:52 am, RolandRB wrote: > On 26 Jul, 17:31, webonomic wrote: > > > > > I want to populate N observations with a random value for each > > variable (X, Y, Z) in a dataset. > > Each variable in the dataset can only have a certain range of values. > > > X must be a random whole number with values of 1, 2, 3, or 4. > > Y must be a either a 1 or 0, assigned randomly. > > Z is dependant on Y. If Y = 0 than Z in (1,2,3) Else If Y = 1 than Z > > in (4,5,6) > > > My result dataset would look something like this: > > > id X Y Z > > 1 3 0 3 > > 2 4 0 2 > > 3 1 1 5 > > 4 4 0 2 > > 5 2 1 6 > > 6 2 0 1 > > 7 4 0 3 > > 8 1 1 4 > > 9 3 1 5 > > ... > > N 3 1 6 > > > Thanks in advance. I have been searching about random number > > generation as well as creating simulating test trial datasets, but > > nothing has come up for choosing a random value from a set of known > > values. > > > Jared > > This is how to get 1,2,3 or 4 randomly. The rest you can work out. > > data _null_; > do i=1 to 20; > x=floor(ranuni(8)*4)+1; > put x=; > end; > run; ```

Back to: Top of message | Previous page | Main SAS-L page