LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
              chosen values
In-Reply-To:  <1185467804.802608.119630@i13g2000prf.googlegroups.com>
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; > 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,

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,

Dan

Daniel J. Nordlund Research and Data Analysis Washington State Department of Social and Health Services Olympia, WA 98504-5204


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