Date: Thu, 26 Jul 2007 10:05:35 -0700
Reply-To: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject: Re: Generate observations with a specific range of randomly
Content-Type: text/plain; charset=iso-8859-1
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> Behalf Of webonomic
> Sent: Thursday, July 26, 2007 9:37 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Generate observations with a specific range of
> randomly chosen values
> 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;
> if y=0 then z=floor(ranuni(8)*3)+1;
> else z=floor(ranuni(8)*3)+4;
> 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).
I see you have a solution to your problem. Just a couple of quick points.
1. remember to change the seed for the RANUNI function each time you run the data step unless you want the same numbers you got in the previous run.
2. You can use the CEIL function instead of the FLOOR function to eliminate some additions, e.g., ceil(ranuni(seed)*4) will generate uniform integers on the range of 1-4 without the need to add 1.
3. to generate your 0,1 y variable you could also use
y=ranuni(seed) GT 0.5;
Hope this is helpful,
Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA 98504-5204