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 (January 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 18 Jan 2010 05:14:24 -0600
Reply-To:     Warren Schlechte <Warren.Schlechte@TPWD.STATE.TX.US>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Warren Schlechte <Warren.Schlechte@TPWD.STATE.TX.US>
Subject:      Re: assign a unique random integer to each unique id
Content-Type: text/plain; charset="iso-8859-1"

Here's what I would do:

Extract just the ids: proc sql; select unique id, ranuni as random ;from dataset; order by random; Then using a datastep, do: data dataset; set dataset; if _n_=1 then integer=1; else integer+1; Then merge this dataset back into the original dataset.

Warren Schlechte

-----Original Message----- From: Nordlund, Dan (DSHS/RDA) [mailto:NordlDJ@DSHS.WA.GOV] Sent: Fri 1/15/2010 7:11 PM Subject: Re: assign a unique random integer to each unique id

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Ai > Hua Wang > Sent: Friday, January 15, 2010 8:10 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: assign a unique random integer to each unique id > > Hi, > > I was wondering if anybody in this list could advise how I can assign a unique > random integer to each unique id. I have written the following code but it does not > allow me to get the unique random intergers. The 10000000 is proportional to the > size of the data set. Do I miss anything in the codes? Please kindly provide your > suggestions. > > Thanks, > Aihua > > > data temp; > set datset1; > urand=ceil(ranuni(1)*10000000); > run; > >

Aihua,

Well, without knowing what you are going to use those "random" numbers for, it is hard to give good advice. Why does your multiplier need to be proportional to dataset size? Why do you want random integers assigned to your data? And why do they need to be unique? If you tell us more about what your actual needs are, we might be able to provide better help.

That being said, the following code will assign unique integers to your data, as long as you have fewer than 2**31 - 1 records.

data want; if _n_=1 then do; **----urand will be your random integer----**; urand=0; call ranuni(urand,dummy); **get a starting seed; put "original seed = " urand; **"save" starting seed to log; retain urand ; end;

set datset1; call ranuni(urand,dummy);

drop dummy; run;

Hope this is helpful,

Dan

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


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