Date: Thu, 16 Feb 2012 22:07:38 +0400
Reply-To: sourav ghosh <mujamailkaro2010@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: sourav ghosh <mujamailkaro2010@GMAIL.COM>
Subject: Re: random no generator with probability
In-Reply-To: <F7E6D18CC2877149AB5296CE54EA276603C4D6@WAXMXOLYMB001.WAX.wa.lcl>
Content-Type: text/plain; charset=windows-1252
Hi,
here for every value their is an unique seed , so each time the seed will
be change., I am not sure it is possible or not.. but I have received an
algorithem code
PROC IMPORT OUT= WORK.SAMPLE
DATAFILE= "D:\temp\sample.xls"
DBMS=EXCEL5 REPLACE;
GETNAMES=YES;
RUN;
proc summary
data=Work.Sample;
var
MEMBER_ID;
class GENDER
REGION;
output out=WORK.SUMMARY(drop = _TYPE_
_FREQ_)
N
=
SUM
=
/
autoname;
run;
PROC SQL;
CREATE TABLE WORK.GET_RAND AS
SELECT t1.gender,
t1.region,
t1.member_id_N as count,
t1.member_id_Sum as SEED,
/* seed */
(md5(put(t1.member_id_Sum,10.0))) FORMAT=$hex32. AS RANDOM,
mod(t1.member_id_N,5) AS Remainder,
floor(t1.member_id_N/5)*5 as round_down,
put(t1.member_id_SUM,10.0) as INPUT_MD5,
(ifn((md5(put(t1.member_id_Sum,10.0)))>('33333333333333333333333333333333'x),5,0))
AS COMPARE1,
(ifn((md5(put(t1.member_id_Sum,10.0)))>('66666666666666666666666666666666'x),5,0))
AS COMPARE2,
(ifn((md5(put(t1.member_id_Sum,10.0)))>('99999999999999999999999999999999'x),5,0))
AS COMPARE3,
(ifn((md5(put(t1.member_id_Sum,10.0)))>('CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'x),5,0))
AS COMPARE4,
(ifn((md5(put(t1.member_id_Sum,10.0)))>('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'x),5,0))
AS COMPARE5
/*(ifn((md5(put(t1.member_id_Sum,10.0)))<('33333333333333333333333333333333'x*(mod(t1.member_id_N,5))),0,5))
AS COMPARE_ALL*/
FROM WORK.SUMMARY AS t1;
QUIT;
PROC SQL;
CREATE TABLE WORK.RULES AS
SELECT t1.gender,
t1.region,
t1.member_id_N as count,
t1.member_id_Sum as SEED,
mod(t1.member_id_N,5) AS Remainder,
floor(t1.member_id_N/5)*5 +
(ifn((md5(put(t1.member_id_Sum,10.0)))>('33333333333333333333333333333333'x),5,0))
AS Remainder5_rule,
floor(t1.member_id_N/5)*5 +
(ifn((md5(put(t1.member_id_Sum,10.0)))>('66666666666666666666666666666666'x),5,0))
AS Remainder4_rule,
floor(t1.member_id_N/5)*5 +
(ifn((md5(put(t1.member_id_Sum,10.0)))>('99999999999999999999999999999999'x),5,0))
AS Remainder2_rule,
floor(t1.member_id_N/5)*5 +
(ifn((md5(put(t1.member_id_Sum,10.0)))>('CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'x),5,0))
AS Remainder1_rule,
floor(t1.member_id_N/5)*5 +
(ifn((md5(put(t1.member_id_Sum,10.0)))>('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'x),5,0))
AS Remainder0_rule
FROM WORK.SUMMARY AS t1;
QUIT;
Notes: MD5: produces a 128-bit (16-byte) hash value****
typically expressed as a 32-digit hexadecimal number****
range in hex: 00000000000000000000000000000000 –
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
But I am nt clear abt the code & logic
On Thu, Feb 16, 2012 at 8:49 PM, Nordlund, Dan (DSHS/RDA) <
NordlDJ@dshs.wa.gov> wrote:
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> > "SUBSCRIBE SAS-L Anonymous"sourav
> > Sent: Thursday, February 16, 2012 2:31 AM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: random no generator with probability
> >
> > Hi frds,
> > I need help from you folks about random no generator
> >
> > step1: I have 2 dataset A & B both have dimension n*m(always will be
> > same)
> >
> > DATAset A contains all values
> > DATAset B contains all seed for the values
> > ex: If value in dataset A's cell 1*1 is "7" then the seed for the value
> > is
> > belong to
> > dataset B in cell 1*1
> >
> >
> > step2:
> > Round all values down to nearest multiple of 5
> > floor(value\5)*5
> >
> > Step 3:
> >
> > take the mod of the VALUE.
> >
> > 1. value mod 5 == 0, with p=5/5 add 0, p=0/5 add 5
> > 2. value mod 5 == 1, with p=4/5 add 0, p=1/5 add 5
> >
> > 3. value mod 5 == 2, with p=3/5 add 0, p=2/5 add 5
> > 4. value mod 5 == 3, with p=2/5 add 0, p=3/5 add 5
> > 5. value mod 5 == 4, with p=1/5 add 0, p=4/5 add 5
> >
> > i LIKE TO DEVOLEP THE ALGORITHEM
> > INITIALLY i have plan to use RANBIN function
> > like floor(value\5)*5 + 5*ranbin(seed,n,p)
> >
> > but facing difficulty in terms of mapping the seed and numbers and
> > providing the value of n, I guess p is the probability of getting the
> > value 1
> >
> >
>
> I would agree with Rick Wicklin that it is unclear what you are trying to
> do. It IS possible to change the seed for some of the random number
> generators within a data step, but it is not clear (at least to me) whether
> one should ever do that. At the very least, you should think long and hard
> before doing it, and you should know exactly how the pseudorandom numbers
> are generated and how changing the seed could affect the quality of the
> "randomness" of the numbers generated. If you write back to SAS-L and
> provide more detail on what your overall project is trying to do, you will
> probably get more useful suggestions. In addition to Rick's suggestions,
> you might take a look at this article on SASCommunity.org
>
> http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work
>
>
> 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
>
|