Date: Fri, 17 Feb 2012 10:32:29 +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: <F7E6D18CC2877149AB5296CE54EA276603C64A@WAXMXOLYMB001.WAX.wa.lcl>
Content-Type: text/plain; charset=windows-1252
ok, forgot about the code..let try it with one by one step
step1:
I have 2 dataset A & B both have dimension n*m(both the dataset always
will be
same dimension)
prob: I want to write a programe where each value like cell(1*1) of A
will reference from cell (1*1) B.
like in ranuni function
new value=ranuni(old value,seed)
here old value is cell(1*1) of A and seed is cell (1*1) of B .. so
similarly sequence will happen for all sell of N*M dimension
step2:
I want a function which will generate either 0 and 1 with following prob.
May be RANBIN function will do, Also the function have the seed option like
RANBIN(seed,n,p) not sure what will be value for n for each following cases,
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
step3:
now I will do relace the A(1*1) with the new random value generating with
respect to seed and above probabilies
Now I think we can think one by one step
On Thu, Feb 16, 2012 at 10:57 PM, Nordlund, Dan (DSHS/RDA) <
NordlDJ@dshs.wa.gov> wrote:
> Well, I haven’t spent enough time looking at the code to understand the
> logic or what the desired output is. But, I don’t see any place in the
> code where random numbers are being generated. The md5() function isn’t
> designed to produce ‘random’ numbers but, as you noted in your email, it is
> a hashing function.
>
> I may be slow on the uptake, but I still don’t know what you are trying to
> do. If you have the code below and it does what you need, why aren’t you
> using it? What am I missing here? If it doesn’t do what you need and you
> are trying to adapt it, then I would need to understand what you are trying
> to do before I can suggest anything. Of course, even if you explain what
> you are trying to do, I may not be able to help :-( ….but someone else
> might.
>
> 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
>
> From: sourav ghosh [mailto:mujamailkaro2010@gmail.com]
> Sent: Thursday, February 16, 2012 10:08 AM
> To: Nordlund, Dan (DSHS/RDA)
> Cc: SAS-L@listserv.uga.edu
> Subject: Re: random no generator with probability
>
> 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<mailto:NordlDJ@dshs.wa.gov>> wrote:
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU<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<mailto: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
>
>
|